mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-09-30 20:06:51 +03:00
Compare commits
7
Commits
8e20a321cb
...
5437192289
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5437192289 | ||
|
|
aaf96522f4 | ||
|
|
5f66220d2e | ||
|
|
7b277a0956 | ||
|
|
ea4dcb875a | ||
|
|
b45f0cdf66 | ||
|
|
2e647040d8 |
@@ -75,6 +75,12 @@ http {
|
||||
vod_align_segments_to_key_frames on;
|
||||
vod_manifest_segment_durations_mode accurate;
|
||||
vod_ignore_edit_list on;
|
||||
# short leading segments at each playlist start; sources start at
|
||||
# the seek target, so the ladder applies to every seek. Only
|
||||
# effective when clips declare real keyFrameDurations
|
||||
vod_bootstrap_segment_durations 1000;
|
||||
vod_bootstrap_segment_durations 2000;
|
||||
vod_bootstrap_segment_durations 4000;
|
||||
vod_segment_duration 10000;
|
||||
|
||||
# MPEG-TS settings (not used when fMP4 is enabled, kept for reference)
|
||||
|
||||
@@ -252,16 +252,14 @@ birdseye:
|
||||
# 1 is the highest quality, and 31 is the lowest. Lower quality feeds utilize less CPU resources.
|
||||
quality: 8
|
||||
# Optional: Activity types that include cameras in Birdseye (default: shown below)
|
||||
# Multiple activity types can be enabled at the same time.
|
||||
mode:
|
||||
# Optional: All cameras are included always (default: shown below)
|
||||
continuous: False
|
||||
# Optional: Cameras are included if motion was detected in the last 30 seconds (default: shown below)
|
||||
motion: False
|
||||
# Optional: Cameras are included if they have had an active tracked object within the last 30 seconds (default: shown below)
|
||||
objects: True
|
||||
# Optional: Cameras are included while they have a stationary tracked object (default: shown below)
|
||||
stationary_objects: False
|
||||
# Multiple activity types can be listed at the same time.
|
||||
# continuous: all cameras are included always
|
||||
# motion: included if motion was detected within the inactivity threshold
|
||||
# all_objects: included if a tracked object was present within the inactivity threshold
|
||||
# alerts: included while an alert review item is in progress
|
||||
# detections: included while a detection review item is in progress
|
||||
modes:
|
||||
- all_objects
|
||||
# Optional: Threshold for camera activity to stop showing camera (default: shown below)
|
||||
inactivity_threshold: 30
|
||||
# Optional: Configure the birdseye layout
|
||||
|
||||
@@ -20,12 +20,15 @@ Each camera tile in Birdseye is composed from the frames of the stream assigned
|
||||
|
||||
### Birdseye Activity Types
|
||||
|
||||
Birdseye offers independent activity types that control when cameras are shown. Multiple activity types can be enabled together.
|
||||
Birdseye offers independent activity types that control when cameras are shown. Multiple activity types can be listed together.
|
||||
|
||||
- **continuous:** The camera is always included
|
||||
- **motion:** The camera is included when motion was detected within the last 30 seconds
|
||||
- **objects:** The camera is included when an active object was tracked within the last 30 seconds
|
||||
- **stationary_objects:** The camera is included while a stationary object is tracked
|
||||
- **all_objects:** The camera is included when a tracked object is present, active or stationary
|
||||
- **alerts:** The camera is included while an alert review item is in progress
|
||||
- **detections:** The camera is included while a detection review item is in progress
|
||||
|
||||
`alerts` and `detections` follow the review item's own lifetime, so the camera is removed as soon as the review item ends. Which objects qualify for each is set in [review configuration](./review.md).
|
||||
|
||||
### Custom Birdseye Icon
|
||||
|
||||
@@ -50,20 +53,19 @@ To include a camera in Birdseye view only for specific circumstances, or exclude
|
||||
</TabItem>
|
||||
<TabItem value="yaml">
|
||||
|
||||
```yaml {8-11,13-15}
|
||||
```yaml {10-12,15-16}
|
||||
# Include all cameras by default in Birdseye view
|
||||
birdseye:
|
||||
enabled: True
|
||||
mode:
|
||||
continuous: True
|
||||
modes:
|
||||
- continuous
|
||||
|
||||
cameras:
|
||||
front:
|
||||
# Only include the "front" camera in Birdseye view when objects are detected
|
||||
# Only include the "front" camera in Birdseye view when an alert is in progress
|
||||
birdseye:
|
||||
mode:
|
||||
continuous: False
|
||||
objects: True
|
||||
modes:
|
||||
- alerts
|
||||
back:
|
||||
# Exclude the "back" camera from Birdseye view
|
||||
birdseye:
|
||||
@@ -75,7 +77,7 @@ cameras:
|
||||
|
||||
### Birdseye Inactivity
|
||||
|
||||
By default birdseye shows all cameras that have had the configured activity in the last 30 seconds. This threshold can be configured.
|
||||
By default birdseye shows all cameras that have had the configured activity in the last 30 seconds. This threshold can be configured, and applies to the `motion` and `all_objects` activity types only.
|
||||
|
||||
<ConfigTabs>
|
||||
<TabItem value="ui">
|
||||
@@ -144,7 +146,8 @@ Navigate to <NavPath path="Settings > System > Birdseye" /> and in the **Camera
|
||||
# Include all cameras by default in Birdseye view
|
||||
birdseye:
|
||||
enabled: True
|
||||
mode: continuous
|
||||
modes:
|
||||
- continuous
|
||||
|
||||
cameras:
|
||||
front:
|
||||
|
||||
@@ -421,7 +421,7 @@ As a general rule, features that read recordings prefer the main stream and fall
|
||||
| Audio extraction (e.g., transcription) | Main preferred, sub fallback |
|
||||
| Motion search | Main only |
|
||||
| Review timeline motion data | Main only |
|
||||
| Storage usage statistics | Both streams counted |
|
||||
| Storage usage statistics | Both streams counted, and listed separately per camera |
|
||||
|
||||
This table covers only features that read recordings from disk. Tracked object snapshots and thumbnails (the images shown in Explore and sent with notifications, and the images submitted to Frigate+ from a tracked object) are captured live from the `detect` stream as the object is tracked, never from recordings, so sub stream recording does not affect them.
|
||||
|
||||
|
||||
@@ -553,23 +553,25 @@ must be enabled in the configuration.
|
||||
|
||||
Topic with current state of Birdseye for a camera. Published values are `ON` and `OFF`.
|
||||
|
||||
### `frigate/<camera_name>/birdseye_mode/set`
|
||||
### `frigate/<camera_name>/birdseye_modes/set`
|
||||
|
||||
Topic to set the Birdseye activity types for a camera. Send one uppercase activity type or combine multiple types with commas, for example `MOTION,OBJECTS,STATIONARY_OBJECTS`.
|
||||
Topic to set the Birdseye activity types for a camera. Send one uppercase activity type or combine multiple types with commas, for example `MOTION,ALERTS`.
|
||||
|
||||
_Note: Changing the value from `CONTINUOUS` to non-continuous activity types will take up to 30 seconds for
|
||||
the camera to be removed from the view._
|
||||
|
||||
| Command | Description |
|
||||
| -------------------- | ---------------------------------------------------------------- |
|
||||
| `CONTINUOUS` | Always included |
|
||||
| `MOTION` | Shown if motion was detected within the last 30 seconds |
|
||||
| `OBJECTS` | Shown if an active object was tracked within the last 30 seconds |
|
||||
| `STATIONARY_OBJECTS` | Shown while a stationary object is tracked |
|
||||
| Command | Description |
|
||||
| ------------- | ---------------------------------------------------------------- |
|
||||
| `CONTINUOUS` | Always included |
|
||||
| `MOTION` | Shown if motion was detected within the last 30 seconds |
|
||||
| `ALL_OBJECTS` | Shown if a tracked object was present within the last 30 seconds |
|
||||
| `ALERTS` | Shown while an alert review item is in progress |
|
||||
| `DETECTIONS` | Shown while a detection review item is in progress |
|
||||
| `NONE` | Never included |
|
||||
|
||||
### `frigate/<camera_name>/birdseye_mode/state`
|
||||
### `frigate/<camera_name>/birdseye_modes/state`
|
||||
|
||||
Topic with the current Birdseye activity types for a camera. Multiple enabled types are published as a comma-separated value in the order `OBJECTS`, `MOTION`, `STATIONARY_OBJECTS`, `CONTINUOUS`.
|
||||
Topic with the current Birdseye activity types for a camera. Multiple enabled types are published as a comma-separated value in the order `CONTINUOUS`, `MOTION`, `ALL_OBJECTS`, `ALERTS`, `DETECTIONS`. `NONE` is published when no activity types are enabled.
|
||||
|
||||
### `frigate/<camera_name>/notifications/set`
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -713,7 +713,7 @@ paths:
|
||||
| `improve_contrast` | `ON`, `OFF` |
|
||||
| `ptz_autotracker` | `ON`, `OFF` |
|
||||
| `birdseye` | `ON`, `OFF` |
|
||||
| `birdseye_mode` | `CONTINUOUS`, `MOTION`, `OBJECTS` |
|
||||
| `birdseye_modes` | `CONTINUOUS`, `MOTION`, `ALL_OBJECTS`, `ALERTS`, `DETECTIONS`, `NONE`, or a comma-separated combination |
|
||||
| `motion_contour_area` | integer |
|
||||
| `motion_threshold` | integer |
|
||||
| `motion_mask` | `ON`, `OFF` |
|
||||
@@ -803,7 +803,7 @@ paths:
|
||||
| `improve_contrast` | `ON`, `OFF` |
|
||||
| `ptz_autotracker` | `ON`, `OFF` |
|
||||
| `birdseye` | `ON`, `OFF` |
|
||||
| `birdseye_mode` | `CONTINUOUS`, `MOTION`, `OBJECTS` |
|
||||
| `birdseye_modes` | `CONTINUOUS`, `MOTION`, `ALL_OBJECTS`, `ALERTS`, `DETECTIONS`, `NONE`, or a comma-separated combination |
|
||||
| `motion_contour_area` | integer |
|
||||
| `motion_threshold` | integer |
|
||||
| `motion_mask` | `ON`, `OFF` |
|
||||
|
||||
@@ -1386,7 +1386,7 @@ def camera_set(
|
||||
| `improve_contrast` | `ON`, `OFF` |
|
||||
| `ptz_autotracker` | `ON`, `OFF` |
|
||||
| `birdseye` | `ON`, `OFF` |
|
||||
| `birdseye_mode` | `CONTINUOUS`, `MOTION`, `OBJECTS` |
|
||||
| `birdseye_modes` | `CONTINUOUS`, `MOTION`, `ALL_OBJECTS`, `ALERTS`, `DETECTIONS`, `NONE`, or a comma-separated combination |
|
||||
| `motion_contour_area` | integer |
|
||||
| `motion_threshold` | integer |
|
||||
| `motion_mask` | `ON`, `OFF` |
|
||||
|
||||
+12
-3
@@ -598,7 +598,15 @@ def _build_vod_clip(
|
||||
clip: dict[str, Any] = {"type": "source", "path": row.path}
|
||||
if plan.clip_from_ms is not None:
|
||||
clip["clipFrom"] = plan.clip_from_ms
|
||||
clip["keyFrameDurations"] = [plan.duration_ms]
|
||||
if plan.key_frame_durations is not None:
|
||||
# real gaps enable keyframe-aligned sub-file segments (bootstrap
|
||||
# ladder); the whole-clip fallback keeps one segment per file,
|
||||
# the only safe cut without an index
|
||||
if plan.first_key_frame_offset_ms > 0:
|
||||
clip["firstKeyFrameOffset"] = plan.first_key_frame_offset_ms
|
||||
clip["keyFrameDurations"] = plan.key_frame_durations
|
||||
else:
|
||||
clip["keyFrameDurations"] = [plan.duration_ms]
|
||||
logger.debug(
|
||||
"VOD: added clip %s duration_ms=%s clipFrom=%s",
|
||||
row.path,
|
||||
@@ -740,14 +748,15 @@ async def _vod_response(
|
||||
NGINX_VOD_MAX_CLIPS,
|
||||
)
|
||||
|
||||
# segmentation comes from the vod_* nginx directives plus per-clip
|
||||
# keyFrameDurations; a segment_duration field here was always ignored
|
||||
# (nginx-vod parses only camelCase segmentDuration)
|
||||
hour_ago = datetime.now() - timedelta(hours=1)
|
||||
content = {
|
||||
"cache": hour_ago.timestamp() > start_ts,
|
||||
"discontinuity": force_discontinuity or use_discontinuity,
|
||||
"consistentSequenceMediaInfo": True,
|
||||
"durations": durations,
|
||||
# aligns segments to recording file boundaries
|
||||
"segment_duration": max(durations),
|
||||
"sequences": [{"clips": clips}],
|
||||
}
|
||||
if use_discontinuity:
|
||||
|
||||
+83
-40
@@ -71,7 +71,7 @@ def get_recordings_storage_usage(request: Request):
|
||||
|
||||
|
||||
@router.get("/recordings/summary", dependencies=[Depends(allow_any_authenticated())])
|
||||
def all_recordings_summary(
|
||||
async def all_recordings_summary(
|
||||
request: Request,
|
||||
params: MediaRecordingsSummaryQueryParams = Depends(),
|
||||
allowed_cameras: list[str] = Depends(get_allowed_cameras_for_filter),
|
||||
@@ -88,18 +88,23 @@ def all_recordings_summary(
|
||||
else:
|
||||
camera_list = allowed_cameras
|
||||
|
||||
time_range_query = (
|
||||
Recordings.select(
|
||||
fn.MIN(Recordings.start_time).alias("min_time"),
|
||||
fn.MAX(Recordings.start_time).alias("max_time"),
|
||||
min_time: float | None = None
|
||||
max_time: float | None = None
|
||||
for camera in camera_list:
|
||||
cam_min = (
|
||||
Recordings.select(fn.MIN(Recordings.start_time))
|
||||
.where(Recordings.camera == camera)
|
||||
.scalar()
|
||||
)
|
||||
.where(Recordings.camera << camera_list)
|
||||
.dicts()
|
||||
.get()
|
||||
)
|
||||
|
||||
min_time = time_range_query.get("min_time")
|
||||
max_time = time_range_query.get("max_time")
|
||||
if cam_min is None:
|
||||
continue
|
||||
cam_max = (
|
||||
Recordings.select(fn.MAX(Recordings.start_time))
|
||||
.where(Recordings.camera == camera)
|
||||
.scalar()
|
||||
)
|
||||
min_time = cam_min if min_time is None else min(min_time, cam_min)
|
||||
max_time = cam_max if max_time is None else max(max_time, cam_max)
|
||||
|
||||
if min_time is None or max_time is None:
|
||||
return JSONResponse(content={})
|
||||
@@ -109,22 +114,60 @@ def all_recordings_summary(
|
||||
days: dict[str, bool] = {}
|
||||
|
||||
for period_start, period_end, period_offset in dst_periods:
|
||||
day_expr = ((Recordings.start_time + period_offset) / 86400).cast("int")
|
||||
first_start = max(min_time, period_start - MAX_SEGMENT_DURATION)
|
||||
first_day = int((first_start + period_offset) // 86400)
|
||||
last_day = int((min(max_time, period_end) + period_offset) // 86400)
|
||||
|
||||
period_query = (
|
||||
Recordings.select(day_expr.alias("day_idx"))
|
||||
.where(
|
||||
(Recordings.camera << camera_list)
|
||||
& (Recordings.end_time >= period_start)
|
||||
& (Recordings.start_time <= period_end)
|
||||
day_idx = first_day
|
||||
while day_idx <= last_day:
|
||||
day_str = (dt.date(1970, 1, 1) + dt.timedelta(days=day_idx)).isoformat()
|
||||
day_start = day_idx * 86400 - period_offset
|
||||
day_end = day_start + 86400
|
||||
|
||||
if day_str in days:
|
||||
day_idx += 1
|
||||
continue
|
||||
|
||||
if day_end <= period_end:
|
||||
upper = Recordings.start_time < day_end
|
||||
else:
|
||||
upper = Recordings.start_time <= period_end
|
||||
|
||||
has_recordings = (
|
||||
Recordings.select(Recordings.id)
|
||||
.where(
|
||||
(Recordings.camera << camera_list)
|
||||
& (Recordings.end_time >= period_start)
|
||||
& (Recordings.start_time >= day_start)
|
||||
& upper
|
||||
)
|
||||
.exists()
|
||||
)
|
||||
.distinct()
|
||||
.namedtuples()
|
||||
)
|
||||
if has_recordings:
|
||||
days[day_str] = True
|
||||
day_idx += 1
|
||||
continue
|
||||
|
||||
for g in period_query:
|
||||
day_str = (dt.date(1970, 1, 1) + dt.timedelta(days=g.day_idx)).isoformat()
|
||||
days[day_str] = True
|
||||
# empty day
|
||||
next_start: float | None = None
|
||||
for camera in camera_list:
|
||||
cam_next = (
|
||||
Recordings.select(fn.MIN(Recordings.start_time))
|
||||
.where(
|
||||
Recordings.camera == camera,
|
||||
Recordings.start_time >= day_end,
|
||||
Recordings.start_time <= period_end,
|
||||
)
|
||||
.scalar()
|
||||
)
|
||||
if cam_next is not None and (
|
||||
next_start is None or cam_next < next_start
|
||||
):
|
||||
next_start = cam_next
|
||||
|
||||
if next_start is None:
|
||||
break
|
||||
day_idx = max(day_idx + 1, int((next_start + period_offset) // 86400))
|
||||
|
||||
return JSONResponse(content=dict(sorted(days.items())))
|
||||
|
||||
@@ -373,22 +416,22 @@ async def no_recordings(
|
||||
)
|
||||
scale = params.scale
|
||||
|
||||
clauses = [
|
||||
(Recordings.end_time >= after) & (Recordings.start_time <= before),
|
||||
(Recordings.camera << camera_list),
|
||||
]
|
||||
recordings: list[tuple[float, float]] = []
|
||||
for camera in camera_list:
|
||||
recordings.extend(
|
||||
Recordings.select(Recordings.start_time, Recordings.end_time)
|
||||
.where(
|
||||
Recordings.camera == camera,
|
||||
Recordings.start_time >= after - MAX_SEGMENT_DURATION,
|
||||
Recordings.end_time >= after,
|
||||
Recordings.start_time <= before,
|
||||
)
|
||||
.tuples()
|
||||
.iterator()
|
||||
)
|
||||
|
||||
# Get recording start times
|
||||
data: list[Recordings] = (
|
||||
Recordings.select(Recordings.start_time, Recordings.end_time)
|
||||
.where(reduce(operator.and_, clauses))
|
||||
.order_by(Recordings.start_time.asc())
|
||||
.dicts()
|
||||
.iterator()
|
||||
)
|
||||
|
||||
# Convert recordings to list of (start, end) tuples, ordered by start_time
|
||||
recordings = [(r["start_time"], r["end_time"]) for r in data]
|
||||
# the merge pass below expects a single start-ordered timeline
|
||||
recordings.sort()
|
||||
|
||||
# Merge overlapping/adjacent recordings into covered intervals. The query
|
||||
# orders by start_time, so a single pass merges them
|
||||
|
||||
@@ -11,7 +11,11 @@ from frigate.camera.activity_manager import AudioActivityManager, CameraActivity
|
||||
from frigate.comms.base_communicator import Communicator
|
||||
from frigate.comms.runtime_state import RuntimeStatePersistence
|
||||
from frigate.comms.webpush import WebPushClient
|
||||
from frigate.config import BirdseyeModeConfig, FrigateConfig
|
||||
from frigate.config import (
|
||||
FrigateConfig,
|
||||
birdseye_modes_from_mqtt_payload,
|
||||
birdseye_modes_to_mqtt_payload,
|
||||
)
|
||||
from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
CameraConfigUpdatePublisher,
|
||||
@@ -84,7 +88,7 @@ class Dispatcher:
|
||||
"recordings": self._on_recordings_command,
|
||||
"snapshots": self._on_snapshots_command,
|
||||
"birdseye": self._on_birdseye_command,
|
||||
"birdseye_mode": self._on_birdseye_mode_command,
|
||||
"birdseye_modes": self._on_birdseye_modes_command,
|
||||
"review_alerts": self._on_alerts_command,
|
||||
"review_detections": self._on_detections_command,
|
||||
"object_descriptions": self._on_object_description_command,
|
||||
@@ -879,12 +883,12 @@ class Dispatcher:
|
||||
)
|
||||
self.publish(f"{camera_name}/birdseye/state", payload, retain=True)
|
||||
|
||||
def _on_birdseye_mode_command(self, camera_name: str, payload: str) -> None:
|
||||
def _on_birdseye_modes_command(self, camera_name: str, payload: str) -> None:
|
||||
"""Callback for birdseye mode topic."""
|
||||
|
||||
mode = BirdseyeModeConfig.from_mqtt_payload(payload)
|
||||
if mode is None:
|
||||
logger.info("Invalid birdseye_mode command: %s", payload)
|
||||
modes = birdseye_modes_from_mqtt_payload(payload)
|
||||
if modes is None:
|
||||
logger.info("Invalid birdseye_modes command: %s", payload)
|
||||
return
|
||||
|
||||
birdseye_settings = self.config.cameras[camera_name].birdseye
|
||||
@@ -893,9 +897,9 @@ class Dispatcher:
|
||||
logger.info(f"Birdseye mode not enabled for {camera_name}")
|
||||
return
|
||||
|
||||
birdseye_settings.mode = mode
|
||||
birdseye_settings.modes = modes
|
||||
logger.info(
|
||||
f"Setting birdseye mode for {camera_name} to {birdseye_settings.mode}"
|
||||
f"Setting birdseye mode for {camera_name} to {birdseye_settings.modes}"
|
||||
)
|
||||
|
||||
self.config_updater.publish_update(
|
||||
@@ -903,7 +907,9 @@ class Dispatcher:
|
||||
birdseye_settings,
|
||||
)
|
||||
self.publish(
|
||||
f"{camera_name}/birdseye_mode/state", mode.to_mqtt_payload(), retain=True
|
||||
f"{camera_name}/birdseye_modes/state",
|
||||
birdseye_modes_to_mqtt_payload(modes),
|
||||
retain=True,
|
||||
)
|
||||
|
||||
def _on_camera_notification_command(self, camera_name: str, payload: str) -> None:
|
||||
|
||||
@@ -7,7 +7,7 @@ import paho.mqtt.client as mqtt
|
||||
from paho.mqtt.enums import CallbackAPIVersion
|
||||
|
||||
from frigate.comms.base_communicator import Communicator
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config import FrigateConfig, birdseye_modes_to_mqtt_payload
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -123,9 +123,9 @@ class MqttClient(Communicator):
|
||||
retain=True,
|
||||
)
|
||||
self.publish(
|
||||
f"{camera_name}/birdseye_mode/state",
|
||||
f"{camera_name}/birdseye_modes/state",
|
||||
(
|
||||
camera.birdseye.mode.to_mqtt_payload()
|
||||
birdseye_modes_to_mqtt_payload(camera.birdseye.modes)
|
||||
if camera.birdseye.enabled
|
||||
else "OFF"
|
||||
),
|
||||
@@ -270,7 +270,7 @@ class MqttClient(Communicator):
|
||||
"motion_threshold",
|
||||
"motion_contour_area",
|
||||
"birdseye",
|
||||
"birdseye_mode",
|
||||
"birdseye_modes",
|
||||
"review_alerts",
|
||||
"review_detections",
|
||||
"object_descriptions",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from ..base import FrigateBaseModel
|
||||
@@ -6,78 +8,58 @@ __all__ = [
|
||||
"BirdseyeCameraConfig",
|
||||
"BirdseyeConfig",
|
||||
"BirdseyeLayoutConfig",
|
||||
"BirdseyeModeConfig",
|
||||
"BirdseyeModeEnum",
|
||||
"birdseye_modes_from_mqtt_payload",
|
||||
"birdseye_modes_to_mqtt_payload",
|
||||
]
|
||||
|
||||
BIRDSEYE_ACTIVITY_TYPES = (
|
||||
"objects",
|
||||
"motion",
|
||||
"stationary_objects",
|
||||
"continuous",
|
||||
)
|
||||
# canonical MQTT payload for an empty mode list
|
||||
MQTT_NO_MODES = "NONE"
|
||||
|
||||
|
||||
class BirdseyeModeConfig(FrigateBaseModel):
|
||||
continuous: bool = Field(
|
||||
default=False,
|
||||
title="Continuous",
|
||||
description="Always include the camera in Birdseye.",
|
||||
)
|
||||
motion: bool = Field(
|
||||
default=False,
|
||||
title="Motion",
|
||||
description="Include the camera in Birdseye when motion is detected.",
|
||||
)
|
||||
objects: bool = Field(
|
||||
default=False,
|
||||
title="Active objects",
|
||||
description="Include the camera in Birdseye while an active object is tracked.",
|
||||
)
|
||||
stationary_objects: bool = Field(
|
||||
default=False,
|
||||
title="Stationary objects",
|
||||
description="Include the camera in Birdseye while a stationary object is tracked.",
|
||||
)
|
||||
class BirdseyeModeEnum(str, Enum):
|
||||
continuous = "continuous"
|
||||
motion = "motion"
|
||||
all_objects = "all_objects"
|
||||
alerts = "alerts"
|
||||
detections = "detections"
|
||||
|
||||
@classmethod
|
||||
def from_mqtt_payload(cls, payload: str) -> "BirdseyeModeConfig | None":
|
||||
"""Create mode options from an uppercase MQTT payload."""
|
||||
raw_modes = payload.split(",")
|
||||
if not raw_modes or any(not mode for mode in raw_modes):
|
||||
|
||||
def birdseye_modes_from_mqtt_payload(payload: str) -> list[BirdseyeModeEnum] | None:
|
||||
"""Parse an uppercase MQTT payload into activity modes, or None when invalid."""
|
||||
raw_modes = payload.split(",")
|
||||
|
||||
if any(not raw_mode or raw_mode != raw_mode.upper() for raw_mode in raw_modes):
|
||||
return None
|
||||
|
||||
if raw_modes == [MQTT_NO_MODES]:
|
||||
return []
|
||||
|
||||
modes: list[BirdseyeModeEnum] = []
|
||||
|
||||
for raw_mode in raw_modes:
|
||||
try:
|
||||
mode = BirdseyeModeEnum(raw_mode.lower())
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
modes = [mode.lower() for mode in raw_modes]
|
||||
if any(
|
||||
raw_mode != mode.upper() or mode not in BIRDSEYE_ACTIVITY_TYPES
|
||||
for raw_mode, mode in zip(raw_modes, modes)
|
||||
):
|
||||
if mode in modes:
|
||||
return None
|
||||
|
||||
if len(modes) != len(set(modes)):
|
||||
return None
|
||||
modes.append(mode)
|
||||
|
||||
return cls(**{mode: True for mode in modes})
|
||||
|
||||
def has_enabled_activity(self) -> bool:
|
||||
"""Return whether at least one activity type is enabled."""
|
||||
return any(getattr(self, activity) for activity in BIRDSEYE_ACTIVITY_TYPES)
|
||||
|
||||
def to_mqtt_payload(self) -> str:
|
||||
"""Serialize enabled mode options for MQTT state topics."""
|
||||
payload = ",".join(
|
||||
activity.upper()
|
||||
for activity in BIRDSEYE_ACTIVITY_TYPES
|
||||
if getattr(self, activity)
|
||||
)
|
||||
if not payload:
|
||||
raise ValueError("At least one Birdseye activity type must be enabled")
|
||||
|
||||
return payload
|
||||
return modes
|
||||
|
||||
|
||||
def default_birdseye_mode() -> BirdseyeModeConfig:
|
||||
"""Return the default Birdseye mode configuration."""
|
||||
return BirdseyeModeConfig(objects=True)
|
||||
def birdseye_modes_to_mqtt_payload(modes: list[BirdseyeModeEnum]) -> str:
|
||||
"""Serialize activity modes for MQTT state topics."""
|
||||
payload = ",".join(mode.value.upper() for mode in BirdseyeModeEnum if mode in modes)
|
||||
return payload or MQTT_NO_MODES
|
||||
|
||||
|
||||
def default_birdseye_modes() -> list[BirdseyeModeEnum]:
|
||||
"""Return the default Birdseye activity modes."""
|
||||
return [BirdseyeModeEnum.all_objects]
|
||||
|
||||
|
||||
class BirdseyeLayoutConfig(FrigateBaseModel):
|
||||
@@ -101,8 +83,8 @@ class BirdseyeConfig(FrigateBaseModel):
|
||||
title="Enable Birdseye",
|
||||
description="Enable or disable the Birdseye view feature.",
|
||||
)
|
||||
mode: BirdseyeModeConfig = Field(
|
||||
default_factory=default_birdseye_mode,
|
||||
modes: list[BirdseyeModeEnum] = Field(
|
||||
default_factory=default_birdseye_modes,
|
||||
title="Activity types",
|
||||
description="Activity types that include cameras in Birdseye.",
|
||||
)
|
||||
@@ -156,8 +138,8 @@ class BirdseyeCameraConfig(BaseModel):
|
||||
title="Enable Birdseye",
|
||||
description="Enable or disable the Birdseye view feature.",
|
||||
)
|
||||
mode: BirdseyeModeConfig = Field(
|
||||
default_factory=default_birdseye_mode,
|
||||
modes: list[BirdseyeModeEnum] = Field(
|
||||
default_factory=default_birdseye_modes,
|
||||
title="Activity types",
|
||||
description="Activity types that include cameras in Birdseye.",
|
||||
)
|
||||
|
||||
@@ -41,7 +41,7 @@ from .auth import AuthConfig
|
||||
from .base import FrigateBaseModel
|
||||
from .camera import CameraConfig, CameraLiveConfig
|
||||
from .camera.audio import AudioConfig, AudioFilterConfig
|
||||
from .camera.birdseye import BirdseyeConfig, BirdseyeModeConfig
|
||||
from .camera.birdseye import BirdseyeConfig
|
||||
from .camera.detect import DetectConfig
|
||||
from .camera.ffmpeg import FfmpegConfig
|
||||
from .camera.genai import GenAIConfig, GenAIRoleEnum
|
||||
@@ -349,20 +349,8 @@ def verify_required_zones_exist(camera_config: CameraConfig) -> None:
|
||||
|
||||
|
||||
def verify_profile_overrides_match_base(camera_config: CameraConfig) -> None:
|
||||
"""Verify profile overrides against the resolved base camera configuration."""
|
||||
"""Verify that profile zone and mask IDs reference entries defined on the base camera."""
|
||||
for profile_name, profile in camera_config.profiles.items():
|
||||
if profile.birdseye is not None:
|
||||
overrides = profile.birdseye.mode.model_dump(exclude_unset=True)
|
||||
base_mode = camera_config.birdseye.mode.model_dump()
|
||||
resolved_mode = BirdseyeModeConfig.model_validate(
|
||||
deep_merge(overrides, base_mode)
|
||||
)
|
||||
if not resolved_mode.has_enabled_activity():
|
||||
raise ValueError(
|
||||
f"Camera '{camera_config.name}' profile '{profile_name}' must "
|
||||
"enable at least one Birdseye activity type"
|
||||
)
|
||||
|
||||
if profile.zones:
|
||||
for zone_name in profile.zones:
|
||||
if zone_name not in camera_config.zones:
|
||||
@@ -1033,10 +1021,6 @@ class FrigateConfig(FrigateBaseModel):
|
||||
self.cameras[name] = camera_config
|
||||
|
||||
verify_config_roles(camera_config)
|
||||
if not camera_config.birdseye.mode.has_enabled_activity():
|
||||
raise ValueError(
|
||||
f"Camera '{name}' must enable at least one Birdseye activity type"
|
||||
)
|
||||
verify_valid_live_stream_names(self, camera_config)
|
||||
verify_recording_segments_setup_with_reasonable_time(camera_config)
|
||||
verify_zone_objects_are_tracked(camera_config)
|
||||
|
||||
@@ -8,6 +8,7 @@ from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from frigate.config.camera.birdseye import birdseye_modes_to_mqtt_payload
|
||||
from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
CameraConfigUpdatePublisher,
|
||||
@@ -42,9 +43,11 @@ SECTION_STATE_TOPICS: dict[str, list[tuple[str, Callable[[Any], Any]]]] = {
|
||||
"birdseye": [
|
||||
("birdseye", lambda c: "ON" if c.birdseye.enabled else "OFF"),
|
||||
(
|
||||
"birdseye_mode",
|
||||
"birdseye_modes",
|
||||
lambda c: (
|
||||
c.birdseye.mode.to_mqtt_payload() if c.birdseye.enabled else "OFF"
|
||||
birdseye_modes_to_mqtt_payload(c.birdseye.modes)
|
||||
if c.birdseye.enabled
|
||||
else "OFF"
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -453,7 +453,7 @@ def get_tool_definitions(
|
||||
"motion",
|
||||
"enabled",
|
||||
"birdseye",
|
||||
"birdseye_mode",
|
||||
"birdseye_modes",
|
||||
"improve_contrast",
|
||||
"ptz_autotracker",
|
||||
"motion_contour_area",
|
||||
@@ -468,7 +468,7 @@ def get_tool_definitions(
|
||||
],
|
||||
"description": (
|
||||
"The feature to change. Most features accept ON or OFF. "
|
||||
"birdseye_mode accepts CONTINUOUS, MOTION, OBJECTS, STATIONARY_OBJECTS, or a comma-separated combination. "
|
||||
"birdseye_modes accepts CONTINUOUS, MOTION, ALL_OBJECTS, ALERTS, DETECTIONS, NONE, or a comma-separated combination. "
|
||||
"motion_contour_area and motion_threshold accept a number. "
|
||||
"profile accepts a profile name or 'none' to deactivate (requires camera='*')."
|
||||
),
|
||||
|
||||
+72
-36
@@ -17,9 +17,11 @@ import cv2
|
||||
import numpy as np
|
||||
|
||||
from frigate.comms.inter_process import InterProcessRequestor
|
||||
from frigate.config import BirdseyeModeConfig, FfmpegConfig, FrigateConfig
|
||||
from frigate.comms.review_updater import ReviewDataSubscriber
|
||||
from frigate.config import BirdseyeModeEnum, FfmpegConfig, FrigateConfig
|
||||
from frigate.const import BASE_DIR, BIRDSEYE_PIPE, INSTALL_DIR, UPDATE_BIRDSEYE_LAYOUT
|
||||
from frigate.output.ws_auth import ws_has_camera_access
|
||||
from frigate.review.types import SeverityEnum
|
||||
from frigate.util.image import (
|
||||
SharedMemoryFrameManager,
|
||||
copy_yuv_to_position,
|
||||
@@ -33,9 +35,9 @@ logger = logging.getLogger(__name__)
|
||||
class BirdseyeActivity:
|
||||
"""Activity signals used to decide whether a camera is shown in Birdseye."""
|
||||
|
||||
has_active_object: bool
|
||||
has_stationary_object: bool
|
||||
has_object: bool
|
||||
has_motion: bool
|
||||
severity: str | None
|
||||
|
||||
|
||||
def get_standard_aspect_ratio(width: int, height: int) -> tuple[int, int]:
|
||||
@@ -367,6 +369,7 @@ class BirdsEyeFrameManager:
|
||||
settings.detect.height,
|
||||
],
|
||||
"last_active_frame": 0.0,
|
||||
"live_active": False,
|
||||
"current_frame": 0.0,
|
||||
"layout_frame": 0.0,
|
||||
"channel_dims": {
|
||||
@@ -418,16 +421,32 @@ class BirdsEyeFrameManager:
|
||||
channel_dims,
|
||||
)
|
||||
|
||||
def camera_active(
|
||||
def camera_threshold_active(
|
||||
self,
|
||||
mode: BirdseyeModeConfig,
|
||||
modes: list[BirdseyeModeEnum],
|
||||
activity: BirdseyeActivity,
|
||||
) -> bool:
|
||||
"""Return whether activity subject to inactivity_threshold is present."""
|
||||
return (BirdseyeModeEnum.motion in modes and activity.has_motion) or (
|
||||
BirdseyeModeEnum.all_objects in modes and activity.has_object
|
||||
)
|
||||
|
||||
def camera_live_active(
|
||||
self,
|
||||
modes: list[BirdseyeModeEnum],
|
||||
activity: BirdseyeActivity,
|
||||
) -> bool:
|
||||
"""Return whether activity that ends the moment it stops is present."""
|
||||
return (
|
||||
mode.continuous
|
||||
or (mode.motion and activity.has_motion)
|
||||
or (mode.objects and activity.has_active_object)
|
||||
or (mode.stationary_objects and activity.has_stationary_object)
|
||||
BirdseyeModeEnum.continuous in modes
|
||||
or (
|
||||
BirdseyeModeEnum.alerts in modes
|
||||
and activity.severity == SeverityEnum.alert
|
||||
)
|
||||
or (
|
||||
BirdseyeModeEnum.detections in modes
|
||||
and activity.severity == SeverityEnum.detection
|
||||
)
|
||||
)
|
||||
|
||||
def get_camera_coordinates(self) -> dict[str, dict[str, int]]:
|
||||
@@ -459,9 +478,15 @@ class BirdsEyeFrameManager:
|
||||
and self.config.cameras[cam].birdseye.enabled
|
||||
and self.config.cameras[cam].enabled_in_config
|
||||
and self.config.cameras[cam].enabled
|
||||
and cam_data["last_active_frame"] > 0
|
||||
and cam_data["current_frame_time"] - cam_data["last_active_frame"]
|
||||
< self.config.birdseye.inactivity_threshold
|
||||
and (
|
||||
cam_data["live_active"]
|
||||
or (
|
||||
cam_data["last_active_frame"] > 0
|
||||
and cam_data["current_frame_time"]
|
||||
- cam_data["last_active_frame"]
|
||||
< self.config.birdseye.inactivity_threshold
|
||||
)
|
||||
)
|
||||
]
|
||||
)
|
||||
logger.debug(f"Active cameras: {active_cameras}")
|
||||
@@ -478,7 +503,9 @@ class BirdsEyeFrameManager:
|
||||
limited_active_cameras = sorted(
|
||||
active_cameras,
|
||||
key=lambda active_camera: (
|
||||
self.cameras[active_camera]["current_frame_time"]
|
||||
0.0
|
||||
if self.cameras[active_camera]["live_active"]
|
||||
else self.cameras[active_camera]["current_frame_time"]
|
||||
- self.cameras[active_camera]["last_active_frame"]
|
||||
),
|
||||
)
|
||||
@@ -754,10 +781,10 @@ class BirdsEyeFrameManager:
|
||||
|
||||
# disabling birdseye is a little tricky
|
||||
if not camera_config.birdseye.enabled or not camera_config.enabled:
|
||||
# if we've rendered a frame (we have a value for last_active_frame)
|
||||
# then we need to set it to zero
|
||||
if camera_state["last_active_frame"] > 0:
|
||||
# if we've rendered a frame (we have activity state) then clear it
|
||||
if camera_state["last_active_frame"] > 0 or camera_state["live_active"]:
|
||||
camera_state["last_active_frame"] = 0
|
||||
camera_state["live_active"] = False
|
||||
force_update = True
|
||||
else:
|
||||
return False, False
|
||||
@@ -765,12 +792,13 @@ class BirdsEyeFrameManager:
|
||||
# update the last active frame for the camera
|
||||
camera_state["current_frame"] = frame.copy()
|
||||
camera_state["current_frame_time"] = frame_time
|
||||
if self.camera_active(
|
||||
camera_config.birdseye.mode,
|
||||
activity,
|
||||
):
|
||||
modes = camera_config.birdseye.modes
|
||||
|
||||
if self.camera_threshold_active(modes, activity):
|
||||
camera_state["last_active_frame"] = frame_time
|
||||
|
||||
camera_state["live_active"] = self.camera_live_active(modes, activity)
|
||||
|
||||
now = datetime.datetime.now().timestamp()
|
||||
|
||||
# limit output to 10 fps
|
||||
@@ -828,6 +856,8 @@ class Birdseye:
|
||||
self.frame_manager = SharedMemoryFrameManager()
|
||||
self.stop_event = stop_event
|
||||
self.requestor = InterProcessRequestor()
|
||||
self.review_subscriber = ReviewDataSubscriber("")
|
||||
self.review_severity: dict[str, str] = {}
|
||||
self.idle_fps: float = self.config.birdseye.idle_heartbeat_fps
|
||||
self._idle_interval: float | None = (
|
||||
(1.0 / self.idle_fps) if self.idle_fps > 0 else None
|
||||
@@ -858,6 +888,21 @@ class Birdseye:
|
||||
self.birdseye_manager.clear_frame()
|
||||
self.__send_new_frame()
|
||||
|
||||
def check_review_updates(self) -> None:
|
||||
"""Drain review updates so each camera's active severity stays current."""
|
||||
while True:
|
||||
update = self.review_subscriber.check_for_update(timeout=0)
|
||||
|
||||
if update is None:
|
||||
break
|
||||
|
||||
camera = update["after"]["camera"]
|
||||
|
||||
if update["type"] == "end":
|
||||
self.review_severity.pop(camera, None)
|
||||
else:
|
||||
self.review_severity[camera] = update["after"]["severity"]
|
||||
|
||||
def add_camera(self, camera: str) -> None:
|
||||
"""Add a camera to the birdseye manager."""
|
||||
self.birdseye_manager.add_camera(camera)
|
||||
@@ -866,6 +911,7 @@ class Birdseye:
|
||||
def remove_camera(self, camera: str) -> None:
|
||||
"""Remove a camera from the birdseye manager."""
|
||||
self.birdseye_manager.remove_camera(camera)
|
||||
self.review_severity.pop(camera, None)
|
||||
logger.debug(f"Removed camera {camera} from birdseye")
|
||||
|
||||
def write_data(
|
||||
@@ -876,24 +922,13 @@ class Birdseye:
|
||||
frame_time: float,
|
||||
frame: np.ndarray,
|
||||
) -> None:
|
||||
has_active_object = False
|
||||
has_stationary_object = False
|
||||
for tracked_object in current_tracked_objects:
|
||||
if tracked_object["stationary"]:
|
||||
if not tracked_object["false_positive"]:
|
||||
has_stationary_object = True
|
||||
else:
|
||||
# Preserve the existing objects activity behavior, which includes
|
||||
# non-stationary trackers before they are confirmed.
|
||||
has_active_object = True
|
||||
|
||||
if has_active_object and has_stationary_object:
|
||||
break
|
||||
|
||||
activity = BirdseyeActivity(
|
||||
has_active_object=has_active_object,
|
||||
has_stationary_object=has_stationary_object,
|
||||
has_object=any(
|
||||
not tracked_object["false_positive"]
|
||||
for tracked_object in current_tracked_objects
|
||||
),
|
||||
has_motion=bool(motion_boxes),
|
||||
severity=self.review_severity.get(camera),
|
||||
)
|
||||
|
||||
frame_changed, frame_layout_changed = self.birdseye_manager.update(
|
||||
@@ -919,5 +954,6 @@ class Birdseye:
|
||||
self.__send_new_frame()
|
||||
|
||||
def stop(self) -> None:
|
||||
self.review_subscriber.stop()
|
||||
self.converter.join()
|
||||
self.broadcaster.join()
|
||||
|
||||
@@ -188,6 +188,11 @@ class OutputProcess(FrigateProcess):
|
||||
self.config.birdseye = birdseye_config
|
||||
logger.debug("Applied dynamic birdseye config update")
|
||||
|
||||
# drain review updates every iteration, not just when birdseye is
|
||||
# being consumed, so a dropped end never strands a camera
|
||||
if birdseye is not None:
|
||||
birdseye.check_review_updates()
|
||||
|
||||
# check if there is an updated config
|
||||
updates = config_subscriber.check_for_updates()
|
||||
|
||||
|
||||
+39
-17
@@ -167,6 +167,10 @@ class RecordingCleanup(threading.Thread):
|
||||
.where(
|
||||
(Recordings.camera == config.name)
|
||||
& (Recordings.stream_type == stream_type)
|
||||
& (
|
||||
Recordings.start_time
|
||||
< max(continuous_expire_date, motion_expire_date)
|
||||
)
|
||||
& (
|
||||
(
|
||||
(Recordings.end_time < continuous_expire_date)
|
||||
@@ -333,27 +337,45 @@ class RecordingCleanup(threading.Thread):
|
||||
expire_before = (
|
||||
datetime.datetime.now() - datetime.timedelta(days=expire_days)
|
||||
).timestamp()
|
||||
no_camera_recordings = (
|
||||
Recordings.select(
|
||||
Recordings.id,
|
||||
Recordings.path,
|
||||
)
|
||||
.where(
|
||||
Recordings.camera.not_in(list(self.config.cameras.keys())), # type: ignore[call-arg, arg-type, misc]
|
||||
Recordings.end_time < expire_before,
|
||||
)
|
||||
.namedtuples()
|
||||
.iterator()
|
||||
)
|
||||
|
||||
# enumerate the distinct cameras with one index seek each
|
||||
db_cameras: list[str] = []
|
||||
last_camera: str | None = None
|
||||
while True:
|
||||
query = Recordings.select(Recordings.camera)
|
||||
if last_camera is not None:
|
||||
query = query.where(Recordings.camera > last_camera)
|
||||
next_camera = query.order_by(Recordings.camera.asc()).limit(1).scalar()
|
||||
if next_camera is None:
|
||||
break
|
||||
db_cameras.append(next_camera)
|
||||
last_camera = next_camera
|
||||
|
||||
maybe_empty_dirs = set()
|
||||
|
||||
deleted_recordings = set()
|
||||
for recording in no_camera_recordings:
|
||||
recording_path = Path(recording.path)
|
||||
recording_path.unlink(missing_ok=True)
|
||||
deleted_recordings.add(recording.id)
|
||||
maybe_empty_dirs.add(recording_path.parent)
|
||||
for camera in db_cameras:
|
||||
if camera in self.config.cameras:
|
||||
continue
|
||||
|
||||
no_camera_recordings = (
|
||||
Recordings.select(
|
||||
Recordings.id,
|
||||
Recordings.path,
|
||||
)
|
||||
.where(
|
||||
Recordings.camera == camera,
|
||||
Recordings.end_time < expire_before,
|
||||
)
|
||||
.namedtuples()
|
||||
.iterator()
|
||||
)
|
||||
|
||||
for recording in no_camera_recordings:
|
||||
recording_path = Path(recording.path)
|
||||
recording_path.unlink(missing_ok=True)
|
||||
deleted_recordings.add(recording.id)
|
||||
maybe_empty_dirs.add(recording_path.parent)
|
||||
|
||||
logger.debug(f"Expiring {len(deleted_recordings)} recordings")
|
||||
# delete up to 100,000 at a time
|
||||
|
||||
+81
-32
@@ -6,7 +6,7 @@ import threading
|
||||
from multiprocessing.synchronize import Event as MpEvent
|
||||
from pathlib import Path
|
||||
|
||||
from peewee import SQL, fn
|
||||
from peewee import SQL, Case, fn
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import (
|
||||
@@ -35,6 +35,35 @@ class StorageMaintainer(threading.Thread):
|
||||
self.stop_event = stop_event
|
||||
self.camera_storage_stats: dict[str, dict] = {}
|
||||
|
||||
def _recent_stream_bandwidth(
|
||||
self, camera: str, stream_type: str, window: int
|
||||
) -> float | None:
|
||||
"""Average MB/s over a stream's most recent rows, or None if no sample.
|
||||
|
||||
Zero-size rows are excluded inside the projection, not the WHERE
|
||||
clause: a segment_size predicate baits the planner into the
|
||||
(camera, segment_size) index plus a full sort of the camera's
|
||||
history instead of the time-ordered index.
|
||||
"""
|
||||
recent = (
|
||||
Recordings.select(
|
||||
Case(
|
||||
None,
|
||||
[(Recordings.segment_size > 0, bandwidth_equation)],
|
||||
None,
|
||||
).alias("bw")
|
||||
)
|
||||
.where(
|
||||
Recordings.camera == camera,
|
||||
Recordings.stream_type == stream_type,
|
||||
)
|
||||
.order_by(Recordings.start_time.desc())
|
||||
.limit(window)
|
||||
.alias("recent")
|
||||
)
|
||||
avg: float | None = Recordings.select(fn.AVG(SQL("bw"))).from_(recent).scalar()
|
||||
return avg
|
||||
|
||||
def calculate_camera_bandwidth(self) -> None:
|
||||
"""Calculate an average MB/hr for each camera."""
|
||||
for camera in self.config.cameras.keys():
|
||||
@@ -47,9 +76,10 @@ class StorageMaintainer(threading.Thread):
|
||||
if self.camera_storage_stats.get(camera, {}).get("needs_refresh", True):
|
||||
self.camera_storage_stats[camera] = {
|
||||
"needs_refresh": (
|
||||
Recordings.select(fn.COUNT("*"))
|
||||
Recordings.select(Recordings.id)
|
||||
.where(Recordings.camera == camera, Recordings.segment_size > 0)
|
||||
.scalar()
|
||||
.limit(50)
|
||||
.count()
|
||||
< 50
|
||||
)
|
||||
}
|
||||
@@ -58,41 +88,38 @@ class StorageMaintainer(threading.Thread):
|
||||
# type and sum the rates; mixing streams would average small
|
||||
# sub segments against large main segments and underestimate
|
||||
# the true write rate
|
||||
bandwidth = 0
|
||||
bandwidth_by_stream: dict[str, float] = {}
|
||||
for stream_type in (STREAM_TYPE_MAIN, STREAM_TYPE_SUB):
|
||||
try:
|
||||
# Subquery to get last 100 segments, then average their bandwidth
|
||||
last_100 = (
|
||||
Recordings.select(bandwidth_equation.alias("bw"))
|
||||
.where(
|
||||
Recordings.camera == camera,
|
||||
Recordings.segment_size > 0,
|
||||
Recordings.stream_type == stream_type,
|
||||
)
|
||||
.order_by(Recordings.start_time.desc())
|
||||
.limit(100)
|
||||
.alias("recent")
|
||||
avg_bw = self._recent_stream_bandwidth(camera, stream_type, 100)
|
||||
if avg_bw is None:
|
||||
# the recent window can be all zero-size ingest
|
||||
# glitches; look further back before concluding
|
||||
# the stream writes nothing
|
||||
avg_bw = self._recent_stream_bandwidth(
|
||||
camera, stream_type, 1000
|
||||
)
|
||||
if avg_bw is not None:
|
||||
bandwidth_by_stream[stream_type] = round(avg_bw * 3600, 2)
|
||||
|
||||
bandwidth += round(
|
||||
Recordings.select(fn.AVG(SQL("bw")))
|
||||
.from_(last_100)
|
||||
.scalar()
|
||||
* 3600,
|
||||
2,
|
||||
)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
bandwidth = round(bandwidth, 2)
|
||||
bandwidth = round(sum(bandwidth_by_stream.values()), 2)
|
||||
|
||||
if bandwidth > MAX_CALCULATED_BANDWIDTH:
|
||||
logger.warning(
|
||||
f"{camera} has a bandwidth of {bandwidth} MB/hr which exceeds the expected maximum. This typically indicates an issue with the cameras recordings."
|
||||
)
|
||||
# scale each stream so the per stream values still sum to
|
||||
# the clamped total the UI displays alongside them
|
||||
scale = MAX_CALCULATED_BANDWIDTH / bandwidth
|
||||
bandwidth_by_stream = {
|
||||
stream_type: round(value * scale, 2)
|
||||
for stream_type, value in bandwidth_by_stream.items()
|
||||
}
|
||||
bandwidth = MAX_CALCULATED_BANDWIDTH
|
||||
|
||||
self.camera_storage_stats[camera]["bandwidth"] = bandwidth
|
||||
self.camera_storage_stats[camera]["bandwidth_by_stream"] = (
|
||||
bandwidth_by_stream
|
||||
)
|
||||
logger.debug(f"{camera} has a bandwidth of {bandwidth} MiB/hr.")
|
||||
|
||||
def calculate_camera_usages(self) -> dict[str, dict]:
|
||||
@@ -104,20 +131,42 @@ class StorageMaintainer(threading.Thread):
|
||||
if camera.startswith(REPLAY_CAMERA_PREFIX):
|
||||
continue
|
||||
|
||||
camera_storage = (
|
||||
Recordings.select(fn.SUM(Recordings.segment_size))
|
||||
.where(Recordings.camera == camera, Recordings.segment_size != 0)
|
||||
.scalar()
|
||||
stream_usages = {
|
||||
row["stream_type"]: row["usage"] or 0
|
||||
for row in (
|
||||
Recordings.select(
|
||||
Recordings.stream_type,
|
||||
fn.SUM(Recordings.segment_size).alias("usage"),
|
||||
)
|
||||
.where(Recordings.camera == camera, Recordings.segment_size != 0)
|
||||
.group_by(Recordings.stream_type)
|
||||
.dicts()
|
||||
)
|
||||
}
|
||||
stream_bandwidths = self.camera_storage_stats.get(camera, {}).get(
|
||||
"bandwidth_by_stream", {}
|
||||
)
|
||||
|
||||
camera_key = (
|
||||
getattr(self.config.cameras[camera], "friendly_name", None) or camera
|
||||
)
|
||||
usages[camera_key] = {
|
||||
"usage": camera_storage,
|
||||
"usage": sum(stream_usages.values()),
|
||||
"bandwidth": self.camera_storage_stats.get(camera, {}).get(
|
||||
"bandwidth", 0
|
||||
),
|
||||
# only streams with segments on disk are reported, so a camera
|
||||
# keeps its sub entry until sub retention expires those segments.
|
||||
# bandwidth is null rather than 0 when the cache holds no sample
|
||||
# for the stream, since 0 would claim it writes nothing
|
||||
"streams": {
|
||||
stream_type: {
|
||||
"usage": stream_usages[stream_type],
|
||||
"bandwidth": stream_bandwidths.get(stream_type),
|
||||
}
|
||||
for stream_type in (STREAM_TYPE_MAIN, STREAM_TYPE_SUB)
|
||||
if stream_usages.get(stream_type)
|
||||
},
|
||||
}
|
||||
|
||||
return usages
|
||||
|
||||
@@ -7,7 +7,7 @@ from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import ruamel.yaml
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config import BirdseyeModeEnum, FrigateConfig
|
||||
from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
CameraConfigUpdatePublisher,
|
||||
@@ -383,22 +383,15 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
|
||||
Global birdseye only seeds enabled and mode; the camera copies are what
|
||||
the output process actually reads. Sending just the global object makes
|
||||
a worker guess which cameras were inheriting, and the only available
|
||||
guess (mode still equals the previous global) wrongly claims a camera
|
||||
whose explicit yaml mode happens to match.
|
||||
guess (modes still equals the previous global) wrongly claims a camera
|
||||
whose explicit yaml modes happens to match.
|
||||
"""
|
||||
self.minimal_config["birdseye"] = {
|
||||
"enabled": True,
|
||||
"mode": {"motion": True},
|
||||
"modes": ["motion"],
|
||||
}
|
||||
# explicit override that matches the global value being replaced
|
||||
self.minimal_config["cameras"]["front_door"]["birdseye"] = {
|
||||
"mode": {
|
||||
"continuous": False,
|
||||
"motion": True,
|
||||
"objects": False,
|
||||
"stationary_objects": False,
|
||||
}
|
||||
}
|
||||
self.minimal_config["cameras"]["front_door"]["birdseye"] = {"modes": ["motion"]}
|
||||
|
||||
config_path = self._write_config_file()
|
||||
mock_find_config.return_value = config_path
|
||||
@@ -409,16 +402,7 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
|
||||
resp = client.put(
|
||||
"/config/set",
|
||||
json={
|
||||
"config_data": {
|
||||
"birdseye": {
|
||||
"mode": {
|
||||
"continuous": True,
|
||||
"motion": False,
|
||||
"objects": False,
|
||||
"stationary_objects": False,
|
||||
}
|
||||
}
|
||||
},
|
||||
"config_data": {"birdseye": {"modes": ["continuous"]}},
|
||||
"update_topic": "config/birdseye",
|
||||
"requires_restart": 0,
|
||||
},
|
||||
@@ -430,7 +414,7 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
|
||||
mock_publisher.publisher.publish.assert_called_once()
|
||||
topic, settings = mock_publisher.publisher.publish.call_args[0]
|
||||
self.assertEqual(topic, "config/birdseye")
|
||||
self.assertEqual(settings.mode.to_mqtt_payload(), "CONTINUOUS")
|
||||
self.assertEqual(settings.modes, [BirdseyeModeEnum.continuous])
|
||||
|
||||
published = {
|
||||
call[0][0].camera: call[0][1]
|
||||
@@ -445,10 +429,10 @@ class TestConfigSetWildcardPropagation(BaseTestHttp):
|
||||
|
||||
# the override survives, the inheriting camera follows global
|
||||
self.assertEqual(
|
||||
published["front_door"].mode.to_mqtt_payload(), "MOTION"
|
||||
published["front_door"].modes, [BirdseyeModeEnum.motion]
|
||||
)
|
||||
self.assertEqual(
|
||||
published["back_yard"].mode.to_mqtt_payload(), "CONTINUOUS"
|
||||
published["back_yard"].modes, [BirdseyeModeEnum.continuous]
|
||||
)
|
||||
finally:
|
||||
os.unlink(config_path)
|
||||
|
||||
@@ -119,7 +119,6 @@ class TestHttpMedia(BaseTestHttp):
|
||||
] == expected_clips
|
||||
expected_durations = [clip[2] for clip in expected_clips]
|
||||
assert vod["durations"] == expected_durations
|
||||
assert vod["segment_duration"] == max(expected_durations)
|
||||
|
||||
def test_recordings_summary_across_dst_spring_forward(self):
|
||||
"""
|
||||
@@ -481,6 +480,129 @@ class TestHttpMedia(BaseTestHttp):
|
||||
assert "2024-03-10" in summary
|
||||
assert summary["2024-03-10"] is True
|
||||
|
||||
def test_recordings_summary_includes_sub_only_days(self):
|
||||
"""
|
||||
A day covered only by sub-stream rows still gets a day marker.
|
||||
|
||||
Retention can expire main rows while keeping sub history, so the
|
||||
calendar must not filter by stream type.
|
||||
"""
|
||||
march_9_utc = datetime(2024, 3, 9, 12, 0, 0, tzinfo=UTC).timestamp()
|
||||
march_10_utc = datetime(2024, 3, 10, 12, 0, 0, tzinfo=UTC).timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording(
|
||||
"main_march_9", march_9_utc, march_9_utc + 3600, stream_type="main"
|
||||
)
|
||||
self._insert_recording(
|
||||
"sub_march_10", march_10_utc, march_10_utc + 3600, stream_type="sub"
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
"/recordings/summary", params={"timezone": "utc", "cameras": "all"}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
summary = response.json()
|
||||
assert len(summary) == 2
|
||||
assert summary["2024-03-09"] is True
|
||||
assert summary["2024-03-10"] is True
|
||||
|
||||
def test_recordings_summary_sparse_days_across_large_gap(self):
|
||||
"""
|
||||
Only recorded days are reported when a large empty gap separates them.
|
||||
"""
|
||||
early = datetime(2023, 1, 5, 12, 0, 0, tzinfo=UTC).timestamp()
|
||||
late = datetime(2024, 3, 10, 12, 0, 0, tzinfo=UTC).timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording("early_day", early, early + 3600)
|
||||
self._insert_recording("late_day", late, late + 3600)
|
||||
|
||||
response = client.get(
|
||||
"/recordings/summary", params={"timezone": "utc", "cameras": "all"}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
summary = response.json()
|
||||
assert summary == {"2023-01-05": True, "2024-03-10": True}
|
||||
|
||||
def test_recordings_unavailable_merges_cameras(self):
|
||||
"""
|
||||
Gaps are computed against the union of all requested cameras' coverage.
|
||||
"""
|
||||
|
||||
async def allow_both_cameras(request: Request):
|
||||
return ["front_door", "back_door"]
|
||||
|
||||
self.app.dependency_overrides[get_allowed_cameras_for_filter] = (
|
||||
allow_both_cameras
|
||||
)
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
for id, camera, start, end in [
|
||||
("front_a", "front_door", 1000, 1100),
|
||||
("front_b", "front_door", 1200, 1300),
|
||||
("back_a", "back_door", 1100, 1160),
|
||||
]:
|
||||
Recordings.insert(
|
||||
id=id,
|
||||
path=f"/media/recordings/{id}.mp4",
|
||||
camera=camera,
|
||||
start_time=start,
|
||||
end_time=end,
|
||||
duration=end - start,
|
||||
motion=0,
|
||||
objects=0,
|
||||
).execute()
|
||||
|
||||
response = client.get(
|
||||
"/recordings/unavailable",
|
||||
params={
|
||||
"after": 1000,
|
||||
"before": 1300,
|
||||
"scale": 10,
|
||||
"cameras": "front_door,back_door",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [{"start_time": 1160, "end_time": 1200}]
|
||||
|
||||
# single camera: back_door alone leaves both edges uncovered
|
||||
response = client.get(
|
||||
"/recordings/unavailable",
|
||||
params={
|
||||
"after": 1000,
|
||||
"before": 1300,
|
||||
"scale": 10,
|
||||
"cameras": "back_door",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [
|
||||
{"start_time": 1000, "end_time": 1100},
|
||||
{"start_time": 1160, "end_time": 1300},
|
||||
]
|
||||
|
||||
def test_recordings_summary_day_attribution_by_start_time(self):
|
||||
"""
|
||||
A recording spanning midnight marks only its start day.
|
||||
"""
|
||||
# starts 23:30 March 9, ends 00:30 March 10 (UTC)
|
||||
start = datetime(2024, 3, 9, 23, 30, 0, tzinfo=UTC).timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording("midnight_span", start, start + 3600)
|
||||
|
||||
response = client.get(
|
||||
"/recordings/summary", params={"timezone": "utc", "cameras": "all"}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
summary = response.json()
|
||||
assert len(summary) == 1
|
||||
assert summary["2024-03-09"] is True
|
||||
|
||||
def _insert_recording(
|
||||
self,
|
||||
id: str,
|
||||
@@ -585,7 +707,6 @@ class TestHttpMedia(BaseTestHttp):
|
||||
"/media/recordings/main_1.mp4",
|
||||
"/media/recordings/main_2.mp4",
|
||||
]
|
||||
assert body["segment_duration"] == 10000
|
||||
|
||||
def test_vod_merges_intervals_split_by_other_stream_boundaries(self):
|
||||
"""A recording spanning several coverage intervals stays one clip.
|
||||
@@ -790,7 +911,6 @@ class TestHttpMedia(BaseTestHttp):
|
||||
assert "initialClipIndex" not in body
|
||||
assert body["consistentSequenceMediaInfo"] is True
|
||||
assert body["durations"] == [10000, 10000]
|
||||
assert body["segment_duration"] == 10000
|
||||
assert len(body["sequences"]) == 1
|
||||
clips = body["sequences"][0]["clips"]
|
||||
assert [c["path"] for c in clips] == [
|
||||
@@ -853,8 +973,8 @@ class TestHttpMedia(BaseTestHttp):
|
||||
A long sub-only stretch means the merged sequence mixes muxed
|
||||
main files and audio-less sub files. Track-PRESENCE mixing
|
||||
across discontinuities is unproven in MSE, so every clip is
|
||||
stripped to video tracks rather than the tracks being carried
|
||||
through the discontinuity the stream mix already forces.
|
||||
stripped to video tracks (the cross-stream hand-off still serves
|
||||
the range in discontinuity mode).
|
||||
"""
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording("main_1", 1000, 1010, "main", has_audio=True)
|
||||
@@ -1240,7 +1360,8 @@ class TestHttpMedia(BaseTestHttp):
|
||||
"""Uniformly-unknown rows (the pre-feature case) are never stripped.
|
||||
|
||||
Legacy rows have has_audio NULL and audio_rate NULL; they share a
|
||||
single signature, so no audio policy fires and audio plays.
|
||||
single signature, so audio plays (the cross-stream hand-off still
|
||||
serves the range in discontinuity mode).
|
||||
"""
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording("main_1", 1000, 1010, "main")
|
||||
|
||||
+241
-37
@@ -4,7 +4,12 @@ import multiprocessing as mp
|
||||
import unittest
|
||||
from unittest.mock import Mock
|
||||
|
||||
from frigate.config import BirdseyeModeConfig, FrigateConfig
|
||||
from frigate.config import (
|
||||
BirdseyeModeEnum,
|
||||
FrigateConfig,
|
||||
birdseye_modes_from_mqtt_payload,
|
||||
birdseye_modes_to_mqtt_payload,
|
||||
)
|
||||
from frigate.output.birdseye import (
|
||||
Birdseye,
|
||||
BirdseyeActivity,
|
||||
@@ -215,11 +220,7 @@ class TestBirdseyeActivity(unittest.TestCase):
|
||||
"mqtt": {"enabled": False},
|
||||
"birdseye": {
|
||||
"enabled": True,
|
||||
"mode": {
|
||||
"motion": True,
|
||||
"objects": True,
|
||||
"stationary_objects": True,
|
||||
},
|
||||
"modes": ["motion", "all_objects"],
|
||||
},
|
||||
"cameras": {
|
||||
"front": {
|
||||
@@ -234,53 +235,93 @@ class TestBirdseyeActivity(unittest.TestCase):
|
||||
}
|
||||
self.manager = BirdsEyeFrameManager(FrigateConfig(**config), mp.Event())
|
||||
|
||||
def test_existing_modes_keep_their_activity_rules(self):
|
||||
continuous = BirdseyeModeConfig(continuous=True)
|
||||
motion = BirdseyeModeConfig(motion=True)
|
||||
objects = BirdseyeModeConfig(objects=True)
|
||||
def test_each_mode_matches_only_its_own_activity(self):
|
||||
motion_activity = BirdseyeActivity(
|
||||
has_object=False, has_motion=True, severity=None
|
||||
)
|
||||
object_activity = BirdseyeActivity(
|
||||
has_object=True, has_motion=False, severity=None
|
||||
)
|
||||
no_activity = BirdseyeActivity(
|
||||
has_object=False, has_motion=False, severity=None
|
||||
)
|
||||
|
||||
no_activity = BirdseyeActivity(False, False, False)
|
||||
motion_activity = BirdseyeActivity(False, False, True)
|
||||
stationary_activity = BirdseyeActivity(False, True, False)
|
||||
active_object_activity = BirdseyeActivity(True, False, False)
|
||||
assert self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.motion], motion_activity
|
||||
)
|
||||
assert not self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.motion], object_activity
|
||||
)
|
||||
assert self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.all_objects], object_activity
|
||||
)
|
||||
assert not self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.all_objects], motion_activity
|
||||
)
|
||||
assert self.manager.camera_live_active(
|
||||
[BirdseyeModeEnum.continuous], no_activity
|
||||
)
|
||||
|
||||
assert self.manager.camera_active(continuous, no_activity)
|
||||
assert self.manager.camera_active(motion, motion_activity)
|
||||
assert not self.manager.camera_active(motion, stationary_activity)
|
||||
assert self.manager.camera_active(objects, active_object_activity)
|
||||
assert not self.manager.camera_active(objects, stationary_activity)
|
||||
def test_continuous_is_not_threshold_activity(self):
|
||||
no_activity = BirdseyeActivity(
|
||||
has_object=False, has_motion=False, severity=None
|
||||
)
|
||||
|
||||
assert not self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.continuous], no_activity
|
||||
)
|
||||
|
||||
def test_modes_can_be_combined(self):
|
||||
mode = BirdseyeModeConfig(motion=True, stationary_objects=True)
|
||||
modes = [BirdseyeModeEnum.motion, BirdseyeModeEnum.all_objects]
|
||||
|
||||
assert self.manager.camera_active(mode, BirdseyeActivity(False, False, True))
|
||||
assert self.manager.camera_active(mode, BirdseyeActivity(False, True, False))
|
||||
assert not self.manager.camera_active(
|
||||
mode, BirdseyeActivity(False, False, False)
|
||||
assert self.manager.camera_threshold_active(
|
||||
modes, BirdseyeActivity(has_object=False, has_motion=True, severity=None)
|
||||
)
|
||||
assert self.manager.camera_threshold_active(
|
||||
modes, BirdseyeActivity(has_object=True, has_motion=False, severity=None)
|
||||
)
|
||||
assert not self.manager.camera_threshold_active(
|
||||
modes, BirdseyeActivity(has_object=False, has_motion=False, severity=None)
|
||||
)
|
||||
|
||||
def test_stationary_objects_are_independent_from_active_objects(self):
|
||||
stationary_objects = BirdseyeModeConfig(stationary_objects=True)
|
||||
def test_empty_modes_never_activate(self):
|
||||
activity = BirdseyeActivity(has_object=True, has_motion=True, severity=None)
|
||||
|
||||
assert self.manager.camera_active(
|
||||
stationary_objects, BirdseyeActivity(False, True, False)
|
||||
assert not self.manager.camera_threshold_active([], activity)
|
||||
assert not self.manager.camera_live_active([], activity)
|
||||
|
||||
def test_alerts_and_detections_match_review_severity(self):
|
||||
alert = BirdseyeActivity(has_object=False, has_motion=False, severity="alert")
|
||||
detection = BirdseyeActivity(
|
||||
has_object=False, has_motion=False, severity="detection"
|
||||
)
|
||||
assert not self.manager.camera_active(
|
||||
stationary_objects, BirdseyeActivity(True, False, False)
|
||||
idle = BirdseyeActivity(has_object=False, has_motion=False, severity=None)
|
||||
|
||||
assert self.manager.camera_live_active([BirdseyeModeEnum.alerts], alert)
|
||||
assert not self.manager.camera_live_active([BirdseyeModeEnum.alerts], detection)
|
||||
assert not self.manager.camera_live_active([BirdseyeModeEnum.alerts], idle)
|
||||
assert self.manager.camera_live_active([BirdseyeModeEnum.detections], detection)
|
||||
assert not self.manager.camera_live_active([BirdseyeModeEnum.detections], alert)
|
||||
|
||||
def test_review_severity_is_not_threshold_activity(self):
|
||||
alert = BirdseyeActivity(has_object=False, has_motion=False, severity="alert")
|
||||
|
||||
assert not self.manager.camera_threshold_active(
|
||||
[BirdseyeModeEnum.alerts, BirdseyeModeEnum.motion], alert
|
||||
)
|
||||
|
||||
def test_write_data_preserves_active_and_confirms_stationary_activity(self):
|
||||
def test_all_objects_covers_active_and_stationary_objects(self):
|
||||
birdseye = Birdseye.__new__(Birdseye)
|
||||
birdseye.birdseye_manager = Mock()
|
||||
birdseye.birdseye_manager.update.return_value = (False, False)
|
||||
birdseye._idle_interval = None
|
||||
birdseye.review_severity = {}
|
||||
frame = Mock()
|
||||
|
||||
birdseye.write_data(
|
||||
"front",
|
||||
[
|
||||
{"stationary": True, "false_positive": True},
|
||||
{"stationary": False, "false_positive": True},
|
||||
{"stationary": True, "false_positive": False},
|
||||
],
|
||||
[[0, 0, 10, 10]],
|
||||
@@ -289,26 +330,36 @@ class TestBirdseyeActivity(unittest.TestCase):
|
||||
)
|
||||
|
||||
birdseye.birdseye_manager.update.assert_called_once_with(
|
||||
"front", BirdseyeActivity(True, True, True), 1.0, frame
|
||||
"front",
|
||||
BirdseyeActivity(has_object=True, has_motion=True, severity=None),
|
||||
1.0,
|
||||
frame,
|
||||
)
|
||||
|
||||
def test_stationary_false_positive_does_not_activate_birdseye(self):
|
||||
def test_false_positives_do_not_count_as_objects(self):
|
||||
birdseye = Birdseye.__new__(Birdseye)
|
||||
birdseye.birdseye_manager = Mock()
|
||||
birdseye.birdseye_manager.update.return_value = (False, False)
|
||||
birdseye._idle_interval = None
|
||||
birdseye.review_severity = {}
|
||||
frame = Mock()
|
||||
|
||||
birdseye.write_data(
|
||||
"front",
|
||||
[{"stationary": True, "false_positive": True}],
|
||||
[
|
||||
{"stationary": True, "false_positive": True},
|
||||
{"stationary": False, "false_positive": True},
|
||||
],
|
||||
[],
|
||||
1.0,
|
||||
frame,
|
||||
)
|
||||
|
||||
birdseye.birdseye_manager.update.assert_called_once_with(
|
||||
"front", BirdseyeActivity(False, False, False), 1.0, frame
|
||||
"front",
|
||||
BirdseyeActivity(has_object=False, has_motion=False, severity=None),
|
||||
1.0,
|
||||
frame,
|
||||
)
|
||||
|
||||
|
||||
@@ -318,7 +369,7 @@ class TestBirdseyeCameraOrder(unittest.TestCase):
|
||||
def setUp(self):
|
||||
config = {
|
||||
"mqtt": {"enabled": False},
|
||||
"birdseye": {"enabled": True, "mode": {"continuous": True}},
|
||||
"birdseye": {"enabled": True, "modes": ["continuous"]},
|
||||
"cameras": {
|
||||
camera: {
|
||||
"ffmpeg": {
|
||||
@@ -340,6 +391,7 @@ class TestBirdseyeCameraOrder(unittest.TestCase):
|
||||
camera_data["current_frame"] = None
|
||||
camera_data["current_frame_time"] = 1.0
|
||||
camera_data["last_active_frame"] = 1.0
|
||||
camera_data["live_active"] = True
|
||||
|
||||
def layout_order(self) -> list[str]:
|
||||
"""Return the cameras in the order the current layout renders them."""
|
||||
@@ -377,3 +429,155 @@ class TestBirdseyeCameraOrder(unittest.TestCase):
|
||||
|
||||
assert not layout_changed
|
||||
assert self.layout_order() == ["back", "front", "side"]
|
||||
|
||||
|
||||
class TestBirdseyeLiveActivity(unittest.TestCase):
|
||||
"""Test that live activity bypasses the inactivity threshold."""
|
||||
|
||||
def setUp(self):
|
||||
config = {
|
||||
"mqtt": {"enabled": False},
|
||||
"birdseye": {
|
||||
"enabled": True,
|
||||
"modes": ["continuous"],
|
||||
"inactivity_threshold": 30,
|
||||
},
|
||||
"cameras": {
|
||||
camera: {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
|
||||
]
|
||||
},
|
||||
"detect": {"height": 1080, "width": 1920, "fps": 5},
|
||||
}
|
||||
for camera in ("back", "front")
|
||||
},
|
||||
}
|
||||
self.config = FrigateConfig(**config)
|
||||
self.manager = BirdsEyeFrameManager(self.config, mp.Event())
|
||||
|
||||
for camera_data in self.manager.cameras.values():
|
||||
camera_data["current_frame"] = None
|
||||
camera_data["current_frame_time"] = 1000.0
|
||||
camera_data["last_active_frame"] = 0.0
|
||||
camera_data["live_active"] = False
|
||||
|
||||
def test_live_active_camera_is_shown_without_a_recent_active_frame(self):
|
||||
self.manager.cameras["front"]["live_active"] = True
|
||||
|
||||
self.manager.update_frame()
|
||||
|
||||
assert self.manager.active_cameras == {"front"}
|
||||
|
||||
def test_live_active_camera_drops_out_immediately(self):
|
||||
self.manager.cameras["front"]["live_active"] = True
|
||||
self.manager.update_frame()
|
||||
assert self.manager.active_cameras == {"front"}
|
||||
|
||||
self.manager.cameras["front"]["live_active"] = False
|
||||
self.manager.update_frame()
|
||||
|
||||
assert self.manager.active_cameras == set()
|
||||
|
||||
def test_threshold_activity_lingers_then_expires(self):
|
||||
self.manager.cameras["front"]["last_active_frame"] = 980.0
|
||||
self.manager.update_frame()
|
||||
assert self.manager.active_cameras == {"front"}
|
||||
|
||||
self.manager.cameras["front"]["last_active_frame"] = 960.0
|
||||
self.manager.update_frame()
|
||||
|
||||
assert self.manager.active_cameras == set()
|
||||
|
||||
def test_max_cameras_ranks_live_active_cameras_first(self):
|
||||
self.config.birdseye.layout.max_cameras = 1
|
||||
self.manager.cameras["front"]["live_active"] = True
|
||||
self.manager.cameras["back"]["last_active_frame"] = 995.0
|
||||
|
||||
self.manager.update_frame()
|
||||
|
||||
assert self.manager.active_cameras == {"front"}
|
||||
|
||||
|
||||
class TestBirdseyeModePayload(unittest.TestCase):
|
||||
"""Test the MQTT payload contract for Birdseye activity modes."""
|
||||
|
||||
def test_single_mode_round_trips(self):
|
||||
modes = birdseye_modes_from_mqtt_payload("ALERTS")
|
||||
|
||||
assert modes == [BirdseyeModeEnum.alerts]
|
||||
assert birdseye_modes_to_mqtt_payload(modes) == "ALERTS"
|
||||
|
||||
def test_combined_modes_are_published_in_enum_order(self):
|
||||
modes = birdseye_modes_from_mqtt_payload("ALERTS,MOTION")
|
||||
|
||||
assert modes == [BirdseyeModeEnum.alerts, BirdseyeModeEnum.motion]
|
||||
assert birdseye_modes_to_mqtt_payload(modes) == "MOTION,ALERTS"
|
||||
|
||||
def test_none_round_trips_to_an_empty_list(self):
|
||||
assert birdseye_modes_from_mqtt_payload("NONE") == []
|
||||
assert birdseye_modes_to_mqtt_payload([]) == "NONE"
|
||||
|
||||
def test_invalid_payloads_are_rejected(self):
|
||||
for payload in (
|
||||
"UNKNOWN",
|
||||
"motion",
|
||||
"MOTION_OBJECTS",
|
||||
"NONE,MOTION",
|
||||
"MOTION,MOTION",
|
||||
"MOTION,",
|
||||
"",
|
||||
):
|
||||
with self.subTest(payload=payload):
|
||||
assert birdseye_modes_from_mqtt_payload(payload) is None
|
||||
|
||||
|
||||
class TestBirdseyeReviewSeverity(unittest.TestCase):
|
||||
"""Test that review updates drive the per-camera severity map."""
|
||||
|
||||
def setUp(self):
|
||||
self.birdseye = Birdseye.__new__(Birdseye)
|
||||
self.birdseye.review_subscriber = Mock()
|
||||
self.birdseye.review_severity = {}
|
||||
self.birdseye.birdseye_manager = Mock()
|
||||
self.birdseye.birdseye_manager.update.return_value = (False, False)
|
||||
self.birdseye._idle_interval = None
|
||||
|
||||
def _drain(self, *updates):
|
||||
self.birdseye.review_subscriber.check_for_update.side_effect = [*updates, None]
|
||||
self.birdseye.check_review_updates()
|
||||
|
||||
def test_new_segment_sets_severity(self):
|
||||
self._drain({"type": "new", "after": {"camera": "front", "severity": "alert"}})
|
||||
|
||||
assert self.birdseye.review_severity == {"front": "alert"}
|
||||
|
||||
def test_update_upgrades_severity(self):
|
||||
self._drain(
|
||||
{"type": "new", "after": {"camera": "front", "severity": "detection"}},
|
||||
{"type": "update", "after": {"camera": "front", "severity": "alert"}},
|
||||
)
|
||||
|
||||
assert self.birdseye.review_severity == {"front": "alert"}
|
||||
|
||||
def test_end_clears_severity(self):
|
||||
self._drain(
|
||||
{"type": "new", "after": {"camera": "front", "severity": "alert"}},
|
||||
{"type": "end", "after": {"camera": "front", "severity": "alert"}},
|
||||
)
|
||||
|
||||
assert self.birdseye.review_severity == {}
|
||||
|
||||
def test_write_data_passes_the_tracked_severity(self):
|
||||
self.birdseye.review_severity = {"front": "alert"}
|
||||
frame = Mock()
|
||||
|
||||
self.birdseye.write_data("front", [], [], 1.0, frame)
|
||||
|
||||
self.birdseye.birdseye_manager.update.assert_called_once_with(
|
||||
"front",
|
||||
BirdseyeActivity(has_object=False, has_motion=False, severity="alert"),
|
||||
1.0,
|
||||
frame,
|
||||
)
|
||||
|
||||
+23
-96
@@ -8,7 +8,7 @@ import numpy as np
|
||||
from pydantic import ValidationError
|
||||
from ruamel.yaml.constructor import DuplicateKeyError
|
||||
|
||||
from frigate.config import FrigateConfig, RetainModeEnum
|
||||
from frigate.config import BirdseyeModeEnum, FrigateConfig, RetainModeEnum
|
||||
from frigate.const import MODEL_CACHE_DIR
|
||||
from frigate.detectors import DetectorTypeEnum
|
||||
from frigate.util.builtin import deep_merge
|
||||
@@ -171,7 +171,7 @@ class TestConfig(unittest.TestCase):
|
||||
def test_override_birdseye(self):
|
||||
config = {
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"birdseye": {"enabled": True, "mode": {"continuous": True}},
|
||||
"birdseye": {"enabled": True, "modes": ["continuous"]},
|
||||
"cameras": {
|
||||
"back": {
|
||||
"ffmpeg": {
|
||||
@@ -186,7 +186,7 @@ class TestConfig(unittest.TestCase):
|
||||
},
|
||||
"birdseye": {
|
||||
"enabled": False,
|
||||
"mode": {"continuous": False, "motion": True},
|
||||
"modes": ["motion"],
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -194,18 +194,16 @@ class TestConfig(unittest.TestCase):
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
assert not frigate_config.cameras["back"].birdseye.enabled
|
||||
mode = frigate_config.cameras["back"].birdseye.mode
|
||||
assert mode.motion
|
||||
assert not mode.continuous
|
||||
assert not mode.objects
|
||||
assert not mode.stationary_objects
|
||||
assert frigate_config.cameras["back"].birdseye.modes == [
|
||||
BirdseyeModeEnum.motion
|
||||
]
|
||||
|
||||
def test_override_birdseye_non_inheritable(self):
|
||||
config = {
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"birdseye": {
|
||||
"enabled": True,
|
||||
"mode": {"continuous": True},
|
||||
"modes": ["continuous"],
|
||||
"height": 1920,
|
||||
},
|
||||
"cameras": {
|
||||
@@ -229,109 +227,38 @@ class TestConfig(unittest.TestCase):
|
||||
|
||||
def test_inherit_birdseye(self):
|
||||
config = {
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"birdseye": {"enabled": True, "mode": {"continuous": True}},
|
||||
"cameras": {
|
||||
"back": {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
|
||||
]
|
||||
},
|
||||
"detect": {
|
||||
"height": 1080,
|
||||
"width": 1920,
|
||||
"fps": 5,
|
||||
},
|
||||
}
|
||||
},
|
||||
**self.minimal,
|
||||
"birdseye": {"enabled": True, "modes": ["continuous"]},
|
||||
}
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
assert frigate_config.cameras["back"].birdseye.enabled
|
||||
mode = frigate_config.cameras["back"].birdseye.mode
|
||||
assert mode.continuous
|
||||
assert not mode.motion
|
||||
assert not mode.objects
|
||||
assert not mode.stationary_objects
|
||||
assert frigate_config.cameras["back"].birdseye.modes == [
|
||||
BirdseyeModeEnum.continuous
|
||||
]
|
||||
|
||||
def test_combine_birdseye_activity_types(self):
|
||||
def test_camera_modes_replace_the_global_list(self):
|
||||
"""A camera list fully replaces the global one, it does not merge into it."""
|
||||
config = {
|
||||
**self.minimal,
|
||||
"birdseye": {
|
||||
"mode": {
|
||||
"motion": True,
|
||||
"stationary_objects": True,
|
||||
}
|
||||
},
|
||||
"birdseye": {"modes": ["motion", "all_objects"]},
|
||||
}
|
||||
config["cameras"]["back"]["birdseye"] = {"modes": ["alerts"]}
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
mode = frigate_config.cameras["back"].birdseye.mode
|
||||
assert mode.motion
|
||||
assert mode.stationary_objects
|
||||
assert not mode.continuous
|
||||
assert not mode.objects
|
||||
assert frigate_config.cameras["back"].birdseye.modes == [
|
||||
BirdseyeModeEnum.alerts
|
||||
]
|
||||
|
||||
def test_birdseye_requires_an_activity_type(self):
|
||||
def test_camera_can_select_no_modes(self):
|
||||
config = {
|
||||
**self.minimal,
|
||||
"birdseye": {
|
||||
"mode": {
|
||||
"continuous": False,
|
||||
"motion": False,
|
||||
"objects": False,
|
||||
"stationary_objects": False,
|
||||
}
|
||||
},
|
||||
"birdseye": {"modes": ["motion"]},
|
||||
}
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValidationError, "must enable at least one Birdseye activity type"
|
||||
):
|
||||
FrigateConfig(**config)
|
||||
|
||||
def test_camera_can_disable_an_inherited_activity_type(self):
|
||||
config = {
|
||||
**self.minimal,
|
||||
"birdseye": {"mode": {"motion": True, "objects": True}},
|
||||
}
|
||||
config["cameras"]["back"]["birdseye"] = {"mode": {"motion": False}}
|
||||
config["cameras"]["back"]["birdseye"] = {"modes": []}
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
mode = frigate_config.cameras["back"].birdseye.mode
|
||||
assert not mode.motion
|
||||
assert mode.objects
|
||||
|
||||
def test_profile_must_leave_an_activity_type_enabled(self):
|
||||
config = {
|
||||
**self.minimal,
|
||||
"profiles": {"away": {"friendly_name": "Away"}},
|
||||
"birdseye": {"mode": {"objects": True}},
|
||||
}
|
||||
config["cameras"]["back"]["profiles"] = {
|
||||
"away": {"birdseye": {"mode": {"objects": False}}}
|
||||
}
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValidationError, "must enable at least one Birdseye activity type"
|
||||
):
|
||||
FrigateConfig(**config)
|
||||
|
||||
def test_camera_birdseye_activity_types_override_global_values(self):
|
||||
config = {
|
||||
**self.minimal,
|
||||
"birdseye": {"mode": {"motion": True, "objects": True}},
|
||||
}
|
||||
config["cameras"]["back"]["birdseye"] = {
|
||||
"mode": {"motion": False, "stationary_objects": True}
|
||||
}
|
||||
|
||||
frigate_config = FrigateConfig(**config)
|
||||
mode = frigate_config.cameras["back"].birdseye.mode
|
||||
assert not mode.motion
|
||||
assert mode.objects
|
||||
assert mode.stationary_objects
|
||||
assert frigate_config.cameras["back"].birdseye.modes == []
|
||||
|
||||
def test_override_tracked_objects(self):
|
||||
config = {
|
||||
|
||||
@@ -8,7 +8,7 @@ from unittest.mock import MagicMock, patch
|
||||
from frigate.app import FrigateApp
|
||||
from frigate.comms.dispatcher import Dispatcher
|
||||
from frigate.comms.runtime_state import RuntimeStatePersistence
|
||||
from frigate.config import BirdseyeModeConfig
|
||||
from frigate.config import BirdseyeModeEnum
|
||||
|
||||
|
||||
def _make_camera_mock(
|
||||
@@ -53,7 +53,7 @@ def _build_dispatcher(cameras: dict[str, MagicMock]) -> Dispatcher:
|
||||
|
||||
|
||||
class TestBirdseyeModeCommands(unittest.TestCase):
|
||||
"""Verify Birdseye mode commands use the boolean mode contract."""
|
||||
"""Verify Birdseye mode commands use the activity list contract."""
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.camera = _make_camera_mock()
|
||||
@@ -62,30 +62,33 @@ class TestBirdseyeModeCommands(unittest.TestCase):
|
||||
self.dispatcher.publish = MagicMock()
|
||||
|
||||
def test_combined_modes_are_accepted(self) -> None:
|
||||
self.dispatcher._on_birdseye_mode_command(
|
||||
"front_door", "STATIONARY_OBJECTS,MOTION"
|
||||
)
|
||||
self.dispatcher._on_birdseye_modes_command("front_door", "ALERTS,MOTION")
|
||||
|
||||
self.assertEqual(
|
||||
self.camera.birdseye.mode,
|
||||
BirdseyeModeConfig(motion=True, stationary_objects=True),
|
||||
self.camera.birdseye.modes,
|
||||
[BirdseyeModeEnum.alerts, BirdseyeModeEnum.motion],
|
||||
)
|
||||
self.dispatcher.config_updater.publish_update.assert_called_once()
|
||||
self.dispatcher.publish.assert_called_once_with(
|
||||
"front_door/birdseye_mode/state",
|
||||
"MOTION,STATIONARY_OBJECTS",
|
||||
"front_door/birdseye_modes/state",
|
||||
"MOTION,ALERTS",
|
||||
retain=True,
|
||||
)
|
||||
|
||||
def test_single_activity_type_is_accepted(self) -> None:
|
||||
self.dispatcher._on_birdseye_mode_command("front_door", "OBJECTS")
|
||||
self.dispatcher._on_birdseye_modes_command("front_door", "ALL_OBJECTS")
|
||||
|
||||
self.assertEqual(
|
||||
self.camera.birdseye.mode,
|
||||
BirdseyeModeConfig(objects=True),
|
||||
)
|
||||
self.assertEqual(self.camera.birdseye.modes, [BirdseyeModeEnum.all_objects])
|
||||
self.dispatcher.publish.assert_called_once_with(
|
||||
"front_door/birdseye_mode/state", "OBJECTS", retain=True
|
||||
"front_door/birdseye_modes/state", "ALL_OBJECTS", retain=True
|
||||
)
|
||||
|
||||
def test_none_clears_every_activity_type(self) -> None:
|
||||
self.dispatcher._on_birdseye_modes_command("front_door", "NONE")
|
||||
|
||||
self.assertEqual(self.camera.birdseye.modes, [])
|
||||
self.dispatcher.publish.assert_called_once_with(
|
||||
"front_door/birdseye_modes/state", "NONE", retain=True
|
||||
)
|
||||
|
||||
def test_unknown_mode_is_rejected(self) -> None:
|
||||
@@ -93,13 +96,12 @@ class TestBirdseyeModeCommands(unittest.TestCase):
|
||||
"UNKNOWN",
|
||||
"motion",
|
||||
"MOTION_OBJECTS",
|
||||
"NONE",
|
||||
"NONE,MOTION",
|
||||
"MOTION,MOTION",
|
||||
"MOTION,",
|
||||
):
|
||||
with self.subTest(payload=payload):
|
||||
self.dispatcher._on_birdseye_mode_command("front_door", payload)
|
||||
self.dispatcher._on_birdseye_modes_command("front_door", payload)
|
||||
|
||||
self.dispatcher.config_updater.publish_update.assert_not_called()
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config import BirdseyeModeEnum, FrigateConfig
|
||||
from frigate.config.camera.profile import CameraProfileConfig
|
||||
from frigate.config.profile import ProfileDefinitionConfig
|
||||
from frigate.config.profile_manager import PERSISTENCE_FILE, ProfileManager
|
||||
@@ -561,23 +561,22 @@ class TestProfileManager(unittest.TestCase):
|
||||
assert self.config.cameras["front"].enabled is False
|
||||
|
||||
@patch.object(ProfileManager, "_persist_active_profile")
|
||||
def test_profile_can_disable_inherited_birdseye_activity(self, mock_persist):
|
||||
"""A false-only mode override inherits the other base activity types."""
|
||||
def test_profile_replaces_birdseye_activity_modes(self, mock_persist):
|
||||
"""A profile mode list replaces the base list rather than merging into it."""
|
||||
self.config.profiles["away"] = ProfileDefinitionConfig(friendly_name="Away")
|
||||
base_mode = self.config.cameras["front"].birdseye.mode
|
||||
base_mode.motion = True
|
||||
base_mode.objects = True
|
||||
self.config.cameras["front"].birdseye.modes = [
|
||||
BirdseyeModeEnum.motion,
|
||||
BirdseyeModeEnum.all_objects,
|
||||
]
|
||||
self.config.cameras["front"].profiles["away"] = CameraProfileConfig(
|
||||
birdseye={"mode": {"motion": False}}
|
||||
birdseye={"modes": ["alerts"]}
|
||||
)
|
||||
self.manager = ProfileManager(self.config, self.mock_updater)
|
||||
|
||||
err = self.manager.activate_profile("away")
|
||||
|
||||
assert err is None
|
||||
mode = self.config.cameras["front"].birdseye.mode
|
||||
assert not mode.motion
|
||||
assert mode.objects
|
||||
assert self.config.cameras["front"].birdseye.modes == [BirdseyeModeEnum.alerts]
|
||||
|
||||
@patch.object(ProfileManager, "_persist_active_profile")
|
||||
def test_deactivate_restores_enabled(self, mock_persist):
|
||||
|
||||
@@ -49,14 +49,19 @@ class TestRecordingCleanupSubRetention(unittest.TestCase):
|
||||
return RecordingCleanup(config, MagicMock())
|
||||
|
||||
def _insert_recording(
|
||||
self, id: str, stream_type: str, age_days: float, motion: int = 0
|
||||
self,
|
||||
id: str,
|
||||
stream_type: str,
|
||||
age_days: float,
|
||||
motion: int = 0,
|
||||
camera: str = "front_door",
|
||||
) -> None:
|
||||
end_time = (
|
||||
datetime.datetime.now() - datetime.timedelta(days=age_days)
|
||||
).timestamp()
|
||||
Recordings.create(
|
||||
id=id,
|
||||
camera="front_door",
|
||||
camera=camera,
|
||||
path=f"/media/frigate/recordings/{id}.mp4",
|
||||
start_time=end_time - 10,
|
||||
end_time=end_time,
|
||||
@@ -208,3 +213,41 @@ class TestRecordingCleanupSubRetention(unittest.TestCase):
|
||||
|
||||
assert Recordings.get_or_none(Recordings.id == "s_old") is None
|
||||
assert Recordings.get_or_none(Recordings.id == "s_new") is not None
|
||||
|
||||
def test_deleted_camera_recordings_expire(self):
|
||||
# rows for a camera no longer in the config expire by the GLOBAL
|
||||
# record retention window; newer orphan rows and configured-camera
|
||||
# rows are untouched by the deleted-cameras sweep
|
||||
config = FrigateConfig(
|
||||
**{
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"record": {"continuous": {"days": 7}},
|
||||
"cameras": {
|
||||
"front_door": {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{
|
||||
"path": "rtsp://10.0.0.1:554/video",
|
||||
"roles": ["detect", "record"],
|
||||
},
|
||||
]
|
||||
},
|
||||
"record": {"enabled": True, "continuous": {"days": 7}},
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
cleanup = RecordingCleanup(config, MagicMock())
|
||||
self._insert_recording("gone_old", "main", 10, camera="removed_cam")
|
||||
self._insert_recording("gone_new", "main", 5, camera="removed_cam")
|
||||
self._insert_recording("gone_blank", "main", 10, camera="")
|
||||
self._insert_recording("kept", "main", 5)
|
||||
|
||||
cleanup.expire_recordings()
|
||||
|
||||
assert Recordings.get_or_none(Recordings.id == "gone_old") is None
|
||||
assert Recordings.get_or_none(Recordings.id == "gone_new") is not None
|
||||
# empty-string camera names sort before every real name and must
|
||||
# still be enumerated by the sweep
|
||||
assert Recordings.get_or_none(Recordings.id == "gone_blank") is None
|
||||
assert Recordings.get_or_none(Recordings.id == "kept") is not None
|
||||
|
||||
@@ -303,3 +303,74 @@ class TestVodManifestPolicy(CoverageDbTestCase):
|
||||
mapping = self._mapping(1000.0, 1020.0, stream="sub")
|
||||
assert mapping["discontinuity"] is False
|
||||
assert "initialClipIndex" not in mapping
|
||||
|
||||
|
||||
class TestClipKeyFrames(unittest.TestCase):
|
||||
"""Keyframe data emitted for nginx-vod segmentation."""
|
||||
|
||||
def _row(self, keyframes):
|
||||
return SimpleNamespace(
|
||||
path="/tmp/kf.mp4",
|
||||
start_time=1000.0,
|
||||
end_time=1010.0,
|
||||
duration=10.0,
|
||||
keyframes=keyframes,
|
||||
)
|
||||
|
||||
def test_whole_file_clip_emits_keyframe_gaps(self):
|
||||
keyframes = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]
|
||||
plan = plan_clip(self._row(keyframes), 1000.0, 1010.0)
|
||||
assert plan.clip_from_ms is None
|
||||
assert plan.key_frame_durations == [1000] * 9
|
||||
assert plan.first_key_frame_offset_ms == 0
|
||||
|
||||
def test_mid_file_clip_offsets_are_clip_relative(self):
|
||||
# start 3.5s in: clipFrom snaps back to the 3000ms keyframe, so
|
||||
# the emitted offsets must be relative to that snapped start
|
||||
keyframes = [0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000]
|
||||
plan = plan_clip(self._row(keyframes), 1003.5, 1010.0)
|
||||
assert plan.clip_from_ms == 3000
|
||||
assert plan.duration_ms == 7000
|
||||
assert plan.key_frame_durations == [1000] * 6
|
||||
assert plan.first_key_frame_offset_ms == 0
|
||||
|
||||
def test_no_index_reports_none(self):
|
||||
plan = plan_clip(self._row(None), 1000.0, 1010.0)
|
||||
assert plan.key_frame_durations is None
|
||||
|
||||
def test_single_keyframe_in_range_reports_none(self):
|
||||
# one cut point cannot split anything; the manifest falls back
|
||||
# to a whole-clip declaration
|
||||
plan = plan_clip(self._row([0]), 1000.0, 1010.0)
|
||||
assert plan.key_frame_durations is None
|
||||
|
||||
def test_keyframe_on_clip_end_excluded(self):
|
||||
# a keyframe landing exactly on the clip end would only declare
|
||||
# a zero-length tail segment
|
||||
plan = plan_clip(self._row([0, 5000, 10000]), 1000.0, 1010.0)
|
||||
assert plan.key_frame_durations == [5000]
|
||||
|
||||
|
||||
class TestVodManifestKeyFrames(CoverageDbTestCase):
|
||||
"""Mapping emission of real vs placeholder keyFrameDurations."""
|
||||
|
||||
def _clips(self, start, end):
|
||||
response = asyncio.run(_vod_response("front_door", start, end))
|
||||
return json.loads(response.body)["sequences"][0]["clips"]
|
||||
|
||||
def test_indexed_row_emits_real_gaps(self):
|
||||
self._insert(
|
||||
"m1",
|
||||
1000.0,
|
||||
1010.0,
|
||||
"main",
|
||||
keyframes=[0, 2000, 4000, 6000, 8000],
|
||||
)
|
||||
clips = self._clips(1000.0, 1010.0)
|
||||
assert clips[0]["keyFrameDurations"] == [2000, 2000, 2000, 2000]
|
||||
assert "firstKeyFrameOffset" not in clips[0]
|
||||
|
||||
def test_unindexed_row_keeps_whole_clip_placeholder(self):
|
||||
self._insert("m1", 1000.0, 1010.0, "main")
|
||||
clips = self._clips(1000.0, 1010.0)
|
||||
assert clips[0]["keyFrameDurations"] == [10000]
|
||||
|
||||
@@ -11,8 +11,9 @@ from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
from playhouse.sqliteq import SqliteQueueDatabase
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import STREAM_TYPE_MAIN, STREAM_TYPE_SUB
|
||||
from frigate.models import Event, Recordings
|
||||
from frigate.storage import StorageMaintainer
|
||||
from frigate.storage import MAX_CALCULATED_BANDWIDTH, StorageMaintainer
|
||||
from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS
|
||||
|
||||
|
||||
@@ -114,8 +115,16 @@ class TestHttp(unittest.TestCase):
|
||||
)
|
||||
storage.calculate_camera_bandwidth()
|
||||
assert storage.camera_storage_stats == {
|
||||
"front_door": {"bandwidth": 1440, "needs_refresh": True},
|
||||
"back_door": {"bandwidth": 2880, "needs_refresh": True},
|
||||
"front_door": {
|
||||
"bandwidth": 1440,
|
||||
"bandwidth_by_stream": {STREAM_TYPE_MAIN: 1440},
|
||||
"needs_refresh": True,
|
||||
},
|
||||
"back_door": {
|
||||
"bandwidth": 2880,
|
||||
"bandwidth_by_stream": {STREAM_TYPE_MAIN: 2880},
|
||||
"needs_refresh": True,
|
||||
},
|
||||
}
|
||||
|
||||
def test_segment_calculations_with_zero_segments(self):
|
||||
@@ -136,9 +145,198 @@ class TestHttp(unittest.TestCase):
|
||||
)
|
||||
storage.calculate_camera_bandwidth()
|
||||
assert storage.camera_storage_stats == {
|
||||
"front_door": {"bandwidth": 0, "needs_refresh": True},
|
||||
"front_door": {
|
||||
"bandwidth": 0,
|
||||
"bandwidth_by_stream": {},
|
||||
"needs_refresh": True,
|
||||
},
|
||||
}
|
||||
|
||||
def test_segment_calculations_with_recent_zero_segments(self):
|
||||
"""A run of recent zero-size segments must not zero out the bandwidth.
|
||||
|
||||
Older nonzero segments still describe the camera's real write rate.
|
||||
"""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
for i in range(10):
|
||||
_insert_mock_recording(
|
||||
f"nonzero_{i}.frontdoor",
|
||||
os.path.join(self.test_dir, f"nonzero_{i}.tmp"),
|
||||
time_keep + i * 10,
|
||||
time_keep + i * 10 + 10,
|
||||
camera="front_door",
|
||||
seg_size=4,
|
||||
seg_dur=10,
|
||||
)
|
||||
for i in range(100):
|
||||
_insert_mock_recording(
|
||||
f"zero_{i}.frontdoor",
|
||||
os.path.join(self.test_dir, f"zero_{i}.tmp"),
|
||||
time_keep + 1000 + i * 10,
|
||||
time_keep + 1000 + i * 10 + 10,
|
||||
camera="front_door",
|
||||
seg_size=0,
|
||||
seg_dur=10,
|
||||
)
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
assert storage.camera_storage_stats == {
|
||||
"front_door": {
|
||||
"bandwidth": 1440,
|
||||
"bandwidth_by_stream": {STREAM_TYPE_MAIN: 1440},
|
||||
"needs_refresh": True,
|
||||
},
|
||||
}
|
||||
|
||||
def test_camera_usages_split_by_stream_type(self):
|
||||
"""Usage and bandwidth are reported per stream type."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
_insert_mock_recording(
|
||||
"1234567.frontdoor",
|
||||
os.path.join(self.test_dir, "main.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
seg_size=20,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_MAIN,
|
||||
)
|
||||
_insert_mock_recording(
|
||||
"1234568.frontdoor",
|
||||
os.path.join(self.test_dir, "sub.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
seg_size=2,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_SUB,
|
||||
)
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
usages = storage.calculate_camera_usages()
|
||||
|
||||
assert usages["front_door"]["usage"] == 22
|
||||
assert usages["front_door"]["bandwidth"] == 7920
|
||||
assert usages["front_door"]["streams"] == {
|
||||
STREAM_TYPE_MAIN: {"usage": 20, "bandwidth": 7200},
|
||||
STREAM_TYPE_SUB: {"usage": 2, "bandwidth": 720},
|
||||
}
|
||||
|
||||
def test_camera_usages_omits_streams_without_segments(self):
|
||||
"""A camera with no sub segments reports no sub entry."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
_insert_mock_recording(
|
||||
"1234567.frontdoor",
|
||||
os.path.join(self.test_dir, "main.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
seg_size=20,
|
||||
seg_dur=10,
|
||||
)
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
usages = storage.calculate_camera_usages()
|
||||
|
||||
assert usages["front_door"]["usage"] == 20
|
||||
assert usages["front_door"]["streams"] == {
|
||||
STREAM_TYPE_MAIN: {"usage": 20, "bandwidth": 7200},
|
||||
}
|
||||
|
||||
def test_camera_bandwidth_clamp_scales_stream_values(self):
|
||||
"""Clamping the total keeps the per stream values summing to it."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
_insert_mock_recording(
|
||||
"1234567.frontdoor",
|
||||
os.path.join(self.test_dir, "main.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
seg_size=40,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_MAIN,
|
||||
)
|
||||
_insert_mock_recording(
|
||||
"1234568.frontdoor",
|
||||
os.path.join(self.test_dir, "sub.tmp"),
|
||||
time_keep,
|
||||
time_keep + 10,
|
||||
seg_size=4,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_SUB,
|
||||
)
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
stats = storage.camera_storage_stats["front_door"]
|
||||
|
||||
assert stats["bandwidth"] == MAX_CALCULATED_BANDWIDTH
|
||||
assert (
|
||||
round(sum(stats["bandwidth_by_stream"].values()), 2)
|
||||
== MAX_CALCULATED_BANDWIDTH
|
||||
)
|
||||
|
||||
def test_stream_bandwidth_is_none_without_a_cached_sample(self):
|
||||
"""A stream that appears after the bandwidth cache freezes has no estimate.
|
||||
|
||||
Sub stream recording can be toggled on at runtime, so the cache can hold
|
||||
a main-only sample while sub segments are already landing on disk.
|
||||
Reporting 0 there would claim the sub stream costs nothing.
|
||||
"""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
time_keep = datetime.datetime.now().timestamp()
|
||||
for i in range(60):
|
||||
_insert_mock_recording(
|
||||
f"main_{i}.frontdoor",
|
||||
os.path.join(self.test_dir, f"main_{i}.tmp"),
|
||||
time_keep + i * 10,
|
||||
time_keep + i * 10 + 10,
|
||||
seg_size=20,
|
||||
seg_dur=10,
|
||||
)
|
||||
|
||||
# 50 or more segments flips needs_refresh off, freezing the cache
|
||||
storage.calculate_camera_bandwidth()
|
||||
assert storage.camera_storage_stats["front_door"]["needs_refresh"] is False
|
||||
|
||||
for i in range(60):
|
||||
_insert_mock_recording(
|
||||
f"sub_{i}.frontdoor",
|
||||
os.path.join(self.test_dir, f"sub_{i}.tmp"),
|
||||
time_keep + 5000 + i * 10,
|
||||
time_keep + 5000 + i * 10 + 10,
|
||||
seg_size=2,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_SUB,
|
||||
)
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
streams = storage.calculate_camera_usages()["front_door"]["streams"]
|
||||
|
||||
assert streams[STREAM_TYPE_SUB]["usage"] == 120
|
||||
assert streams[STREAM_TYPE_SUB]["bandwidth"] is None
|
||||
assert streams[STREAM_TYPE_MAIN]["bandwidth"] == 7200
|
||||
|
||||
def test_camera_usages_with_no_recordings(self):
|
||||
"""A camera with no segments reports zero usage and no streams."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
storage = StorageMaintainer(config, MagicMock())
|
||||
|
||||
storage.calculate_camera_bandwidth()
|
||||
usages = storage.calculate_camera_usages()
|
||||
|
||||
assert usages["front_door"]["usage"] == 0
|
||||
assert usages["front_door"]["streams"] == {}
|
||||
|
||||
def test_storage_cleanup(self):
|
||||
"""Ensure that all recordings are cleaned up when necessary."""
|
||||
config = FrigateConfig(**self.minimal_config)
|
||||
@@ -297,6 +495,7 @@ def _insert_mock_recording(
|
||||
camera="front_door",
|
||||
seg_size=8,
|
||||
seg_dur=10,
|
||||
stream_type=STREAM_TYPE_MAIN,
|
||||
) -> Event:
|
||||
"""Inserts a basic recording model with a given id."""
|
||||
# we must open the file so storage maintainer will delete it
|
||||
@@ -313,4 +512,5 @@ def _insert_mock_recording(
|
||||
motion=True,
|
||||
objects=True,
|
||||
segment_size=seg_size,
|
||||
stream_type=stream_type,
|
||||
).execute()
|
||||
|
||||
+13
-6
@@ -533,19 +533,26 @@ def _convert_legacy_mask_to_dict(
|
||||
return result
|
||||
|
||||
|
||||
# the 0.18 scalar Birdseye modes, mapped to their activity mode names
|
||||
_LEGACY_BIRDSEYE_MODES = {
|
||||
"continuous": "continuous",
|
||||
"motion": "motion",
|
||||
"objects": "all_objects",
|
||||
}
|
||||
|
||||
|
||||
def _migrate_birdseye_mode(birdseye: dict[str, Any] | None) -> None:
|
||||
"""Convert a scalar Birdseye mode to composable activity types."""
|
||||
"""Convert a scalar Birdseye mode to an activity mode list."""
|
||||
if not birdseye or not isinstance(birdseye.get("mode"), str):
|
||||
return
|
||||
|
||||
legacy_mode = birdseye["mode"]
|
||||
activity_types = ("continuous", "motion", "objects", "stationary_objects")
|
||||
if legacy_mode not in activity_types:
|
||||
|
||||
if legacy_mode not in _LEGACY_BIRDSEYE_MODES:
|
||||
return
|
||||
|
||||
birdseye["mode"] = {
|
||||
activity_type: activity_type == legacy_mode for activity_type in activity_types
|
||||
}
|
||||
del birdseye["mode"]
|
||||
birdseye["modes"] = [_LEGACY_BIRDSEYE_MODES[legacy_mode]]
|
||||
|
||||
|
||||
def migrate_018_0(config: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
|
||||
|
||||
@@ -310,11 +310,18 @@ class ClipPlan:
|
||||
|
||||
clip_from_ms is the keyframe-snapped clipFrom, or None when the whole
|
||||
file is served. skipped means the clip is omitted from the manifest.
|
||||
|
||||
key_frame_durations / first_key_frame_offset_ms carry clip-relative
|
||||
keyframe data for nginx-vod sub-file segmentation; None means no
|
||||
usable index, and the manifest declares one whole-clip segment (the
|
||||
only safe cut without keyframe knowledge).
|
||||
"""
|
||||
|
||||
clip_from_ms: int | None
|
||||
duration_ms: int
|
||||
skipped: bool
|
||||
key_frame_durations: list[int] | None = None
|
||||
first_key_frame_offset_ms: int = 0
|
||||
|
||||
|
||||
def plan_clip(row: Any, start: float, end: float) -> ClipPlan:
|
||||
@@ -378,7 +385,38 @@ def plan_clip(row: Any, start: float, end: float) -> ClipPlan:
|
||||
logger.warning(f"Recording clip is missing or empty: {row.path}")
|
||||
return ClipPlan(None, 0, True)
|
||||
|
||||
return ClipPlan(clip_from, duration, False)
|
||||
return ClipPlan(
|
||||
clip_from,
|
||||
duration,
|
||||
False,
|
||||
*_clip_key_frames(row.keyframes, clip_from, duration),
|
||||
)
|
||||
|
||||
|
||||
def _clip_key_frames(
|
||||
keyframes: Any, clip_from: int | None, duration: int
|
||||
) -> tuple[list[int] | None, int]:
|
||||
"""Clip-relative keyframe gaps and first offset for a served range.
|
||||
|
||||
nginx-vod validates firstKeyFrameOffset against the clip duration,
|
||||
so offsets are clip-relative. A keyframe exactly on the clip end is
|
||||
excluded (it would declare a zero-length tail), and fewer than two
|
||||
keyframes returns (None, 0): one cut point cannot split anything.
|
||||
"""
|
||||
if not keyframes:
|
||||
return None, 0
|
||||
|
||||
clip_start = clip_from if clip_from is not None else 0
|
||||
relative = [
|
||||
int(k) - clip_start
|
||||
for k in keyframes
|
||||
if clip_start <= k < clip_start + duration
|
||||
]
|
||||
|
||||
if len(relative) < 2:
|
||||
return None, 0
|
||||
|
||||
return [b - a for a, b in zip(relative, relative[1:])], relative[0]
|
||||
|
||||
|
||||
def realized_timeline(
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
"""Peewee migrations -- 037_add_recordings_stream_index.py.
|
||||
|
||||
Some examples (model - class or model name)::
|
||||
|
||||
> Model = migrator.orm['model_name'] # Return model in current state by name
|
||||
|
||||
> migrator.sql(sql) # Run custom SQL
|
||||
> migrator.python(func, *args, **kwargs) # Run python code
|
||||
> migrator.create_model(Model) # Create a model (could be used as decorator)
|
||||
> migrator.remove_model(model, cascade=True) # Remove a model
|
||||
> migrator.add_fields(model, **fields) # Add fields to a model
|
||||
> migrator.change_fields(model, **fields) # Change fields
|
||||
> migrator.remove_fields(model, *field_names, cascade=True)
|
||||
> migrator.rename_field(model, old_field_name, new_field_name)
|
||||
> migrator.rename_table(model, new_table_name)
|
||||
> migrator.add_index(model, *col_names, unique=False)
|
||||
> migrator.drop_index(model, *col_names)
|
||||
> migrator.add_not_null(model, *field_names)
|
||||
> migrator.drop_not_null(model, *field_names)
|
||||
> migrator.add_default(model, field_name, default)
|
||||
|
||||
"""
|
||||
|
||||
import peewee as pw
|
||||
|
||||
SQL = pw.SQL
|
||||
|
||||
|
||||
def migrate(migrator, database, fake=False, **kwargs):
|
||||
# time-ordered per-stream lookups (bandwidth estimation, pinned-stream
|
||||
# queries) need this ordering; without it, a per-stream ORDER BY
|
||||
# start_time query on a camera with no rows for that stream walks the
|
||||
# camera's entire history via per-row table lookups
|
||||
migrator.sql(
|
||||
'CREATE INDEX IF NOT EXISTS "recordings_camera_stream_type_start_time" ON "recordings" ("camera", "stream_type", "start_time" DESC)'
|
||||
)
|
||||
# the 036 index is a strict prefix of the one above, so keeping it
|
||||
# would only add write amplification on the hottest table
|
||||
migrator.sql('DROP INDEX IF EXISTS "recordings_camera_stream_type"')
|
||||
|
||||
|
||||
def rollback(migrator, database, fake=False, **kwargs):
|
||||
pass
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -70,25 +70,9 @@
|
||||
"label": "Enable Birdseye",
|
||||
"description": "Enable or disable the Birdseye view feature."
|
||||
},
|
||||
"mode": {
|
||||
"modes": {
|
||||
"label": "Activity types",
|
||||
"description": "Activity types that include cameras in Birdseye.",
|
||||
"continuous": {
|
||||
"label": "Continuous",
|
||||
"description": "Always include the camera in Birdseye."
|
||||
},
|
||||
"motion": {
|
||||
"label": "Motion",
|
||||
"description": "Include the camera in Birdseye when motion is detected."
|
||||
},
|
||||
"objects": {
|
||||
"label": "Active objects",
|
||||
"description": "Include the camera in Birdseye while an active object is tracked."
|
||||
},
|
||||
"stationary_objects": {
|
||||
"label": "Stationary objects",
|
||||
"description": "Include the camera in Birdseye while a stationary object is tracked."
|
||||
}
|
||||
"description": "Activity types that include cameras in Birdseye."
|
||||
},
|
||||
"order": {
|
||||
"label": "Position",
|
||||
|
||||
@@ -557,25 +557,9 @@
|
||||
"label": "Enable Birdseye",
|
||||
"description": "Enable or disable the Birdseye view feature."
|
||||
},
|
||||
"mode": {
|
||||
"modes": {
|
||||
"label": "Activity types",
|
||||
"description": "Activity types that include cameras in Birdseye.",
|
||||
"continuous": {
|
||||
"label": "Continuous",
|
||||
"description": "Always include the camera in Birdseye."
|
||||
},
|
||||
"motion": {
|
||||
"label": "Motion",
|
||||
"description": "Include the camera in Birdseye when motion is detected."
|
||||
},
|
||||
"objects": {
|
||||
"label": "Active objects",
|
||||
"description": "Include the camera in Birdseye while an active object is tracked."
|
||||
},
|
||||
"stationary_objects": {
|
||||
"label": "Stationary objects",
|
||||
"description": "Include the camera in Birdseye while a stationary object is tracked."
|
||||
}
|
||||
"description": "Activity types that include cameras in Birdseye."
|
||||
},
|
||||
"restream": {
|
||||
"label": "Restream RTSP",
|
||||
|
||||
@@ -1657,6 +1657,16 @@
|
||||
"summary": "{{count}} selected",
|
||||
"empty": "No zones available"
|
||||
},
|
||||
"birdseyeModes": {
|
||||
"summary": "{{count}} selected",
|
||||
"options": {
|
||||
"continuous": "Continuous",
|
||||
"motion": "Motion",
|
||||
"all_objects": "All objects",
|
||||
"alerts": "Alerts",
|
||||
"detections": "Detections"
|
||||
}
|
||||
},
|
||||
"inputRoles": {
|
||||
"summary": "{{count}} roles selected",
|
||||
"empty": "No roles available",
|
||||
@@ -1856,11 +1866,6 @@
|
||||
}
|
||||
},
|
||||
"birdseye": {
|
||||
"trackingMode": {
|
||||
"objects": "Objects",
|
||||
"motion": "Motion",
|
||||
"continuous": "Continuous"
|
||||
},
|
||||
"cameraOrder": {
|
||||
"label": "Camera order",
|
||||
"description": "Drag cameras to set their order in the Birdseye layout.",
|
||||
|
||||
@@ -148,6 +148,10 @@
|
||||
"unused": {
|
||||
"title": "Unused",
|
||||
"tips": "This value may not accurately represent the free space available to Frigate if you have other files stored on your drive beyond Frigate's recordings. Frigate does not track storage usage outside of its recordings."
|
||||
},
|
||||
"subStream": {
|
||||
"information": "Sub Stream Storage Information",
|
||||
"tips": "Cameras that record a sub stream show their Original and Low quality usage separately, using the same names as the quality options in recording playback. Low quality recordings stay on disk until their retention period expires, so this breakdown can still appear for a camera after sub stream recording has been turned off."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -10,29 +10,26 @@ const birdseye: SectionConfigOverrides = {
|
||||
severity: "info",
|
||||
condition: (ctx) => {
|
||||
if (ctx.level !== "camera" || !ctx.fullCameraConfig) return false;
|
||||
const mode = ctx.formData?.mode;
|
||||
if (!mode || typeof mode !== "object" || Array.isArray(mode)) {
|
||||
const modes = ctx.formData?.modes;
|
||||
if (!Array.isArray(modes)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
(mode.objects === true || mode.stationary_objects === true) &&
|
||||
modes.includes("all_objects") &&
|
||||
ctx.fullCameraConfig.detect?.enabled === false
|
||||
);
|
||||
},
|
||||
},
|
||||
],
|
||||
restartRequired: [],
|
||||
fieldOrder: ["enabled", "mode", "order"],
|
||||
fieldOrder: ["enabled", "modes", "order"],
|
||||
hiddenFields: ["order"],
|
||||
advancedFields: [],
|
||||
overrideFields: ["enabled", "mode"],
|
||||
overrideFields: ["enabled", "modes"],
|
||||
uiSchema: {
|
||||
mode: {
|
||||
continuous: { "ui:size": "xs" },
|
||||
motion: { "ui:size": "xs" },
|
||||
objects: { "ui:size": "xs" },
|
||||
stationary_objects: { "ui:size": "xs" },
|
||||
modes: {
|
||||
"ui:widget": "birdseyeModes",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -43,7 +40,7 @@ const birdseye: SectionConfigOverrides = {
|
||||
"width",
|
||||
"height",
|
||||
"quality",
|
||||
"mode",
|
||||
"modes",
|
||||
"layout",
|
||||
"inactivity_threshold",
|
||||
"idle_heartbeat_fps",
|
||||
@@ -59,7 +56,7 @@ const birdseye: SectionConfigOverrides = {
|
||||
"idle_heartbeat_fps",
|
||||
],
|
||||
uiSchema: {
|
||||
mode: {
|
||||
modes: {
|
||||
"ui:after": { render: "BirdseyeCameraReorder" },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -22,6 +22,7 @@ import { ObjectLabelSwitchesWidget } from "./widgets/ObjectLabelSwitchesWidget";
|
||||
import { AudioLabelSwitchesWidget } from "./widgets/AudioLabelSwitchesWidget";
|
||||
import { ReviewLabelSwitchesWidget } from "./widgets/ReviewLabelSwitchesWidget";
|
||||
import { ZoneSwitchesWidget } from "./widgets/ZoneSwitchesWidget";
|
||||
import { BirdseyeModesWidget } from "./widgets/BirdseyeModesWidget";
|
||||
import { ArrayAsTextWidget } from "./widgets/ArrayAsTextWidget";
|
||||
import { FfmpegArgsWidget } from "./widgets/FfmpegArgsWidget";
|
||||
import { GenAIModelWidget } from "./widgets/GenAIModelWidget";
|
||||
@@ -87,6 +88,7 @@ export const frigateTheme: FrigateTheme = {
|
||||
audioLabels: AudioLabelSwitchesWidget,
|
||||
reviewLabels: ReviewLabelSwitchesWidget,
|
||||
zoneNames: ZoneSwitchesWidget,
|
||||
birdseyeModes: BirdseyeModesWidget,
|
||||
timezoneSelect: TimezoneSelectWidget,
|
||||
optionalField: OptionalFieldWidget,
|
||||
semanticSearchModel: SemanticSearchModelWidget,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Birdseye Modes Widget - For selecting Birdseye activity types via switches
|
||||
import type { WidgetProps } from "@rjsf/utils";
|
||||
import { SwitchesWidget } from "./SwitchesWidget";
|
||||
import type { FormContext } from "./SwitchesWidget";
|
||||
|
||||
// order matches BirdseyeModeEnum in frigate/config/camera/birdseye.py
|
||||
const BIRDSEYE_MODES: string[] = [
|
||||
"continuous",
|
||||
"motion",
|
||||
"all_objects",
|
||||
"alerts",
|
||||
"detections",
|
||||
];
|
||||
|
||||
function getBirdseyeModes(): string[] {
|
||||
return BIRDSEYE_MODES;
|
||||
}
|
||||
|
||||
function getBirdseyeModeLabel(mode: string, context?: FormContext): string {
|
||||
const t = context?.t;
|
||||
|
||||
if (!t) {
|
||||
return mode;
|
||||
}
|
||||
|
||||
return t(`configForm.birdseyeModes.options.${mode}`, {
|
||||
ns: "views/settings",
|
||||
defaultValue: mode,
|
||||
});
|
||||
}
|
||||
|
||||
export function BirdseyeModesWidget(props: WidgetProps) {
|
||||
return (
|
||||
<SwitchesWidget
|
||||
{...props}
|
||||
options={{
|
||||
...props.options,
|
||||
getEntities: getBirdseyeModes,
|
||||
getDisplayLabel: getBirdseyeModeLabel,
|
||||
i18nKey: "birdseyeModes",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -16,24 +16,28 @@ import {
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { getUnitSize } from "@/utils/storageUtil";
|
||||
import { CameraStorage, StreamStorage } from "@/types/stats";
|
||||
|
||||
import { CiCircleAlert } from "react-icons/ci";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
type CameraStorage = {
|
||||
[key: string]: {
|
||||
bandwidth: number;
|
||||
usage: number;
|
||||
usage_percent: number;
|
||||
};
|
||||
};
|
||||
|
||||
type TotalStorage = {
|
||||
used: number;
|
||||
camera: number;
|
||||
total: number;
|
||||
};
|
||||
|
||||
type StorageRow = {
|
||||
name: string;
|
||||
usage: number;
|
||||
bandwidth: number;
|
||||
color: string;
|
||||
streams?: {
|
||||
main?: StreamStorage;
|
||||
sub?: StreamStorage;
|
||||
};
|
||||
};
|
||||
|
||||
type CombinedStorageGraphProps = {
|
||||
graphId: string;
|
||||
cameraStorage: CameraStorage;
|
||||
@@ -44,46 +48,59 @@ export function CombinedStorageGraph({
|
||||
cameraStorage,
|
||||
totalStorage,
|
||||
}: CombinedStorageGraphProps) {
|
||||
const { t } = useTranslation(["views/system"]);
|
||||
const { t } = useTranslation(["views/system", "components/player"]);
|
||||
|
||||
const { theme, systemTheme } = useTheme();
|
||||
const isDark = (systemTheme || theme) == "dark";
|
||||
|
||||
const entities = Object.keys(cameraStorage);
|
||||
const colors = generateColors(entities.length);
|
||||
const rows: StorageRow[] = useMemo(() => {
|
||||
const entities = Object.keys(cameraStorage);
|
||||
const colors = generateColors(entities.length);
|
||||
|
||||
const series = entities.map((entity, index) => ({
|
||||
name: entity,
|
||||
data: [(cameraStorage[entity].usage / totalStorage.total) * 100],
|
||||
usage: cameraStorage[entity].usage,
|
||||
bandwidth: cameraStorage[entity].bandwidth,
|
||||
color: colors[index], // Assign the corresponding color
|
||||
}));
|
||||
return [
|
||||
...entities.map((entity, index) => ({
|
||||
name: entity,
|
||||
usage: cameraStorage[entity].usage ?? 0,
|
||||
bandwidth: cameraStorage[entity].bandwidth,
|
||||
color: colors[index],
|
||||
streams: cameraStorage[entity].streams,
|
||||
})),
|
||||
{
|
||||
name: "Other",
|
||||
usage: totalStorage.used - totalStorage.camera,
|
||||
bandwidth: 0,
|
||||
color: isDark ? "#606060" : "#D5D5D5",
|
||||
},
|
||||
{
|
||||
name: "Unused",
|
||||
usage: totalStorage.total - totalStorage.used,
|
||||
bandwidth: 0,
|
||||
color: isDark ? "#404040" : "#E5E5E5",
|
||||
},
|
||||
];
|
||||
}, [cameraStorage, totalStorage, isDark]);
|
||||
|
||||
// Add the unused percentage to the series
|
||||
series.push({
|
||||
name: "Other",
|
||||
data: [
|
||||
((totalStorage.used - totalStorage.camera) / totalStorage.total) * 100,
|
||||
],
|
||||
usage: totalStorage.used - totalStorage.camera,
|
||||
bandwidth: 0,
|
||||
color: (systemTheme || theme) == "dark" ? "#606060" : "#D5D5D5",
|
||||
});
|
||||
series.push({
|
||||
name: "Unused",
|
||||
data: [
|
||||
((totalStorage.total - totalStorage.used) / totalStorage.total) * 100,
|
||||
],
|
||||
usage: totalStorage.total - totalStorage.used,
|
||||
bandwidth: 0,
|
||||
color: (systemTheme || theme) == "dark" ? "#404040" : "#E5E5E5",
|
||||
});
|
||||
const series = useMemo(
|
||||
() =>
|
||||
rows.map((row) => ({
|
||||
name: row.name,
|
||||
data: [(row.usage / totalStorage.total) * 100],
|
||||
usage: row.usage,
|
||||
color: row.color,
|
||||
})),
|
||||
[rows, totalStorage.total],
|
||||
);
|
||||
|
||||
const hasSubStorage = useMemo(
|
||||
() => rows.some((row) => row.streams?.sub),
|
||||
[rows],
|
||||
);
|
||||
|
||||
const options = useMemo(() => {
|
||||
return {
|
||||
chart: {
|
||||
id: graphId,
|
||||
background: (systemTheme || theme) == "dark" ? "#404040" : "#E5E5E5",
|
||||
background: isDark ? "#404040" : "#E5E5E5",
|
||||
selection: {
|
||||
enabled: false,
|
||||
},
|
||||
@@ -164,7 +181,7 @@ export function CombinedStorageGraph({
|
||||
max: 100,
|
||||
},
|
||||
} as ApexCharts.ApexOptions;
|
||||
}, [graphId, systemTheme, theme, series]);
|
||||
}, [graphId, isDark, systemTheme, theme, series]);
|
||||
|
||||
useEffect(() => {
|
||||
ApexCharts.exec(graphId, "updateOptions", options, true, true);
|
||||
@@ -185,6 +202,37 @@ export function CombinedStorageGraph({
|
||||
[t],
|
||||
);
|
||||
|
||||
const getStreamSplit = useCallback(
|
||||
(row: StorageRow, field: keyof StreamStorage) => {
|
||||
const mainValue = row.streams?.main?.[field];
|
||||
const subValue = row.streams?.sub?.[field];
|
||||
|
||||
// omit the split entirely when either side is unknown, rather than
|
||||
// showing a zero that would read as "this stream costs nothing"
|
||||
if (mainValue == null || subValue == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="text-xs text-primary-variant">
|
||||
<div>
|
||||
<span className="text-muted-foreground">
|
||||
{t("quality.main", { ns: "components/player" })}
|
||||
</span>{" "}
|
||||
{getUnitSize(mainValue)}
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">
|
||||
{t("quality.sub", { ns: "components/player" })}
|
||||
</span>{" "}
|
||||
{getUnitSize(subValue)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
[t],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="flex w-full flex-col gap-2.5">
|
||||
<div className="flex w-full items-center justify-between gap-1">
|
||||
@@ -206,7 +254,35 @@ export function CombinedStorageGraph({
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>{t("storage.cameraStorage.camera")}</TableHead>
|
||||
<TableHead>{t("storage.cameraStorage.storageUsed")}</TableHead>
|
||||
<TableHead>
|
||||
<div className="flex flex-row items-center gap-1">
|
||||
{t("storage.cameraStorage.storageUsed")}
|
||||
{hasSubStorage && (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className="focus:outline-none"
|
||||
aria-label={t(
|
||||
"storage.cameraStorage.subStream.information",
|
||||
)}
|
||||
>
|
||||
<CiCircleAlert
|
||||
className="size-5"
|
||||
aria-label={t(
|
||||
"storage.cameraStorage.subStream.information",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<div className="space-y-2">
|
||||
{t("storage.cameraStorage.subStream.tips")}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
</div>
|
||||
</TableHead>
|
||||
<TableHead>
|
||||
{t("storage.cameraStorage.percentageOfTotalUsed")}
|
||||
</TableHead>
|
||||
@@ -214,49 +290,56 @@ export function CombinedStorageGraph({
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{series.map((item) => (
|
||||
<TableRow key={item.name}>
|
||||
<TableCell className="flex flex-row items-center gap-2 font-medium smart-capitalize">
|
||||
{" "}
|
||||
<div
|
||||
className="size-3 rounded-md"
|
||||
style={{ backgroundColor: item.color }}
|
||||
></div>
|
||||
{getItemTitle(item.name)}
|
||||
{(item.name === "Unused" || item.name == "Other") && (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className="focus:outline-none"
|
||||
aria-label={t(
|
||||
"storage.cameraStorage.unusedStorageInformation",
|
||||
)}
|
||||
>
|
||||
<CiCircleAlert
|
||||
className="size-5"
|
||||
{rows.map((row) => {
|
||||
const isAggregate = row.name == "Unused" || row.name == "Other";
|
||||
|
||||
return (
|
||||
<TableRow key={row.name}>
|
||||
<TableCell className="flex flex-row items-center gap-2 font-medium smart-capitalize">
|
||||
<div
|
||||
className="size-3 rounded-md"
|
||||
style={{ backgroundColor: row.color }}
|
||||
></div>
|
||||
{getItemTitle(row.name)}
|
||||
{isAggregate && (
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className="focus:outline-none"
|
||||
aria-label={t(
|
||||
"storage.cameraStorage.unusedStorageInformation",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<div className="space-y-2">
|
||||
{t("storage.cameraStorage.unused.tips")}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>{getUnitSize(item.usage ?? 0)}</TableCell>
|
||||
<TableCell>{item.data[0].toFixed(2)}%</TableCell>
|
||||
<TableCell>
|
||||
{item.name === "Unused" || item.name == "Other"
|
||||
? "—"
|
||||
: `${getUnitSize(item.bandwidth)} / hour`}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
>
|
||||
<CiCircleAlert
|
||||
className="size-5"
|
||||
aria-label={t(
|
||||
"storage.cameraStorage.unusedStorageInformation",
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-80">
|
||||
<div className="space-y-2">
|
||||
{t("storage.cameraStorage.unused.tips")}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{getUnitSize(row.usage)}
|
||||
{getStreamSplit(row, "usage")}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{((row.usage / totalStorage.total) * 100).toFixed(2)}%
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{isAggregate ? "—" : `${getUnitSize(row.bandwidth)} / hour`}
|
||||
{getStreamSplit(row, "bandwidth")}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
|
||||
@@ -45,6 +45,16 @@ import { useUserPersistence } from "@/hooks/use-user-persistence";
|
||||
// a longer buffer cheap and it rides out connection variance better
|
||||
const SUB_STREAM_BUFFER_LENGTH_S = 30;
|
||||
|
||||
// seeks rebuild the source starting at the seek target so the vod
|
||||
// bootstrap segment ladder applies to every seek; quantizing keeps
|
||||
// seek URLs repeatable for nginx's mapping/response caches
|
||||
const SOURCE_START_GRID_S = 10;
|
||||
|
||||
// seeks beyond this bridge the source load with the preview player (the
|
||||
// held video frame is pre-seek content); continuations (quality switch,
|
||||
// natural chunk advance) keep the held frame
|
||||
const REPOSITION_PREVIEW_THRESHOLD_S = 2;
|
||||
|
||||
/**
|
||||
* Dynamically switches between video playback and scrubbing preview player.
|
||||
*/
|
||||
@@ -157,6 +167,11 @@ export default function DynamicVideoPlayer({
|
||||
|
||||
useEffect(() => {
|
||||
if (!isScrubbing) {
|
||||
// never overwrite a pending timer: an orphaned one escapes
|
||||
// onPlaying's clearTimeout and flashes loading mid-playback
|
||||
if (loadingTimeoutRef.current) {
|
||||
clearTimeout(loadingTimeoutRef.current);
|
||||
}
|
||||
loadingTimeoutRef.current = setTimeout(() => setIsLoading(true), 1000);
|
||||
}
|
||||
|
||||
@@ -179,6 +194,85 @@ export default function DynamicVideoPlayer({
|
||||
// playlist, so the playback effect skips its loading indicator
|
||||
const modelOnlyUpdateRef = useRef(false);
|
||||
|
||||
// re-anchors quality-switch rebuilds and classifies rebuilds as
|
||||
// repositioning vs continuation
|
||||
const lastPlayedTimestampRef = useRef<number | undefined>(undefined);
|
||||
|
||||
// start of the current source window within the chunk; undefined plays
|
||||
// from the chunk start. Follows explicit seeks (startTimestamp),
|
||||
// cleared when a chunk change leaves the seek target behind
|
||||
const [sourceAfter, setSourceAfter] = useState<number | undefined>(undefined);
|
||||
|
||||
// adjusted during render: an effect lands one commit late, briefly
|
||||
// painting the stale video frame between drag preview and load bridge
|
||||
const nextSourceAfter =
|
||||
startTimestamp !== undefined &&
|
||||
startTimestamp > timeRange.after &&
|
||||
startTimestamp < timeRange.before
|
||||
? Math.max(
|
||||
timeRange.after,
|
||||
Math.floor(startTimestamp / SOURCE_START_GRID_S) *
|
||||
SOURCE_START_GRID_S,
|
||||
)
|
||||
: undefined;
|
||||
|
||||
if (nextSourceAfter !== sourceAfter) {
|
||||
setSourceAfter(nextSourceAfter);
|
||||
|
||||
const lastPlayed = lastPlayedTimestampRef.current;
|
||||
if (
|
||||
!isLoading &&
|
||||
startTimestamp !== undefined &&
|
||||
lastPlayed !== undefined &&
|
||||
Math.abs(startTimestamp - lastPlayed) > REPOSITION_PREVIEW_THRESHOLD_S
|
||||
) {
|
||||
setIsLoading(true);
|
||||
}
|
||||
}
|
||||
|
||||
// the release anchor lands one commit after isScrubbing flips false
|
||||
// (the view writes playbackStart from an effect), which would flash
|
||||
// the stale frame; hold one commit. The clearing effect runs before
|
||||
// the parent's release effect, so clear and anchor batch into one render
|
||||
const [releaseHold, setReleaseHold] = useState(false);
|
||||
const [wasScrubbing, setWasScrubbing] = useState(isScrubbing);
|
||||
|
||||
if (isScrubbing !== wasScrubbing) {
|
||||
setWasScrubbing(isScrubbing);
|
||||
if (!isScrubbing) {
|
||||
setReleaseHold(true);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (releaseHold) {
|
||||
setReleaseHold(false);
|
||||
}
|
||||
}, [releaseHold]);
|
||||
|
||||
const recordingParams = useMemo(
|
||||
() => ({
|
||||
before: timeRange.before,
|
||||
// clamp: during the adjust-render pass this memo can evaluate with
|
||||
// the previous sourceAfter against a new timeRange
|
||||
after:
|
||||
sourceAfter !== undefined &&
|
||||
sourceAfter > timeRange.after &&
|
||||
sourceAfter < timeRange.before
|
||||
? sourceAfter
|
||||
: timeRange.after,
|
||||
timelines: true,
|
||||
}),
|
||||
[timeRange, sourceAfter],
|
||||
);
|
||||
|
||||
// the window the current source covers; the seek model, in-range
|
||||
// checks, and stale-report guard use this, not the chunk timeRange
|
||||
const sourceTimeRange = useMemo<TimeRange>(
|
||||
() => ({ after: recordingParams.after, before: recordingParams.before }),
|
||||
[recordingParams],
|
||||
);
|
||||
|
||||
const onPlayerLoaded = useCallback(() => {
|
||||
sourceLoadedRef.current = true;
|
||||
governorRef.current?.sourceLoadEnded();
|
||||
@@ -189,9 +283,9 @@ export default function DynamicVideoPlayer({
|
||||
return;
|
||||
}
|
||||
|
||||
// an anchor outside this chunk is stale (e.g. a natural clip
|
||||
// an anchor outside this source window is stale (e.g. a natural clip
|
||||
// advance); the playlist already starts where playback should
|
||||
if (anchor < timeRange.after || anchor > timeRange.before) {
|
||||
if (anchor < sourceTimeRange.after || anchor > sourceTimeRange.before) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -199,11 +293,7 @@ export default function DynamicVideoPlayer({
|
||||
// start it: a mid-drag chunk prefetch can audibly blip before
|
||||
// onPlaying pauses it. The release seek starts playback
|
||||
controller.seekToTimestamp(anchor, !isScrubbing);
|
||||
}, [controller, timeRange, isScrubbing]);
|
||||
|
||||
// used to re-anchor the source when an auto quality switch rebuilds
|
||||
// the playlist mid-playback
|
||||
const lastPlayedTimestampRef = useRef<number | undefined>(undefined);
|
||||
}, [controller, sourceTimeRange, isScrubbing]);
|
||||
|
||||
// the range the controller's playback model was last built for; while
|
||||
// a chunk change awaits its coverage, the outgoing source reports
|
||||
@@ -223,10 +313,10 @@ export default function DynamicVideoPlayer({
|
||||
return;
|
||||
}
|
||||
|
||||
// drop reports until the controller's model matches this chunk
|
||||
// drop reports until the controller's model matches this source
|
||||
if (
|
||||
modelTimeRangeRef.current?.after !== timeRange.after ||
|
||||
modelTimeRangeRef.current?.before !== timeRange.before
|
||||
modelTimeRangeRef.current?.after !== sourceTimeRange.after ||
|
||||
modelTimeRangeRef.current?.before !== sourceTimeRange.before
|
||||
) {
|
||||
return;
|
||||
}
|
||||
@@ -249,7 +339,7 @@ export default function DynamicVideoPlayer({
|
||||
isBuffering,
|
||||
isLoading,
|
||||
isScrubbing,
|
||||
timeRange,
|
||||
sourceTimeRange,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -310,14 +400,6 @@ export default function DynamicVideoPlayer({
|
||||
|
||||
// state of playback player
|
||||
|
||||
const recordingParams = useMemo(
|
||||
() => ({
|
||||
before: timeRange.before,
|
||||
after: timeRange.after,
|
||||
timelines: true,
|
||||
}),
|
||||
[timeRange],
|
||||
);
|
||||
const { data: coverage } = useSWR<RecordingCoverage>(
|
||||
[`${camera}/recordings/coverage`, recordingParams],
|
||||
{ revalidateOnFocus: false },
|
||||
@@ -628,8 +710,8 @@ export default function DynamicVideoPlayer({
|
||||
const anchorTimestamp =
|
||||
qualityChanged &&
|
||||
lastPlayed !== undefined &&
|
||||
lastPlayed >= timeRange.after &&
|
||||
lastPlayed <= timeRange.before
|
||||
lastPlayed >= recordingParams.after &&
|
||||
lastPlayed <= recordingParams.before
|
||||
? lastPlayed
|
||||
: startTimestamp;
|
||||
sourceAnchorRef.current = anchorTimestamp;
|
||||
@@ -679,6 +761,10 @@ export default function DynamicVideoPlayer({
|
||||
HTMLMediaElement.HAVE_CURRENT_DATA;
|
||||
|
||||
if (!modelOnlyUpdate) {
|
||||
// an overwritten pending timer would escape onPlaying's clearTimeout
|
||||
if (loadingTimeoutRef.current) {
|
||||
clearTimeout(loadingTimeoutRef.current);
|
||||
}
|
||||
loadingTimeoutRef.current = setTimeout(
|
||||
() => (hasDecodedFrame ? setIsBuffering(true) : setIsLoading(true)),
|
||||
1000,
|
||||
@@ -687,9 +773,9 @@ export default function DynamicVideoPlayer({
|
||||
|
||||
controller.newPlayback({
|
||||
recordings: recordings ?? [],
|
||||
timeRange,
|
||||
timeRange: sourceTimeRange,
|
||||
});
|
||||
modelTimeRangeRef.current = timeRange;
|
||||
modelTimeRangeRef.current = sourceTimeRange;
|
||||
|
||||
// we only want this to change when controller or recordings update
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -733,7 +819,7 @@ export default function DynamicVideoPlayer({
|
||||
<HlsVideoPlayer
|
||||
videoRef={playerRef}
|
||||
containerRef={containerRef}
|
||||
visible={!(isScrubbing || isLoading)}
|
||||
visible={!(isScrubbing || isLoading || releaseHold)}
|
||||
currentSource={source}
|
||||
hotKeys={hotKeys}
|
||||
supportsFullscreen={supportsFullscreen}
|
||||
@@ -788,7 +874,7 @@ export default function DynamicVideoPlayer({
|
||||
<PreviewPlayer
|
||||
className={cn(
|
||||
className,
|
||||
isScrubbing || isLoading ? "visible" : "hidden",
|
||||
isScrubbing || isLoading || releaseHold ? "visible" : "hidden",
|
||||
)}
|
||||
camera={camera}
|
||||
timeRange={timeRange}
|
||||
|
||||
@@ -480,7 +480,7 @@ export const OVERRIDABLE_SECTIONS: ReadonlyArray<{
|
||||
key: "audio_transcription",
|
||||
compareFields: ["enabled", "live_enabled"],
|
||||
},
|
||||
{ key: "birdseye", compareFields: ["enabled", "mode"] },
|
||||
{ key: "birdseye", compareFields: ["enabled", "modes"] },
|
||||
{ key: "face_recognition", compareFields: ["enabled", "min_area"] },
|
||||
{
|
||||
key: "ffmpeg",
|
||||
|
||||
@@ -13,18 +13,18 @@ export interface UiConfig {
|
||||
export interface BirdseyeConfig {
|
||||
enabled: boolean;
|
||||
height: number;
|
||||
mode: BirdseyeModeConfig;
|
||||
modes: BirdseyeMode[];
|
||||
quality: number;
|
||||
restream: boolean;
|
||||
width: number;
|
||||
}
|
||||
|
||||
export interface BirdseyeModeConfig {
|
||||
continuous: boolean;
|
||||
motion: boolean;
|
||||
objects: boolean;
|
||||
stationary_objects: boolean;
|
||||
}
|
||||
export type BirdseyeMode =
|
||||
| "continuous"
|
||||
| "motion"
|
||||
| "all_objects"
|
||||
| "alerts"
|
||||
| "detections";
|
||||
|
||||
export interface FaceRecognitionConfig {
|
||||
enabled: boolean;
|
||||
@@ -56,7 +56,7 @@ export interface CameraConfig {
|
||||
best_image_timeout: number;
|
||||
birdseye: {
|
||||
enabled: boolean;
|
||||
mode: BirdseyeModeConfig;
|
||||
modes: BirdseyeMode[];
|
||||
order: number;
|
||||
};
|
||||
detect: {
|
||||
|
||||
@@ -101,6 +101,24 @@ export type StorageStats = {
|
||||
shm_frame_count?: number;
|
||||
};
|
||||
|
||||
export type StreamStorage = {
|
||||
usage: number;
|
||||
bandwidth: number | null;
|
||||
};
|
||||
|
||||
export type CameraStorage = {
|
||||
[camera: string]: {
|
||||
bandwidth: number;
|
||||
usage: number;
|
||||
usage_percent: number;
|
||||
// absent for stream types with no segments on disk
|
||||
streams?: {
|
||||
main?: StreamStorage;
|
||||
sub?: StreamStorage;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export type PotentialProblem = {
|
||||
text: string;
|
||||
color: string;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { CombinedStorageGraph } from "@/components/graph/CombinedStorageGraph";
|
||||
import { StorageGraph } from "@/components/graph/StorageGraph";
|
||||
import { FrigateStats } from "@/types/stats";
|
||||
import { CameraStorage, FrigateStats } from "@/types/stats";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import {
|
||||
Popover,
|
||||
@@ -24,14 +24,6 @@ import { LuExternalLink } from "react-icons/lu";
|
||||
import { FaExclamationTriangle } from "react-icons/fa";
|
||||
import ActivityIndicator from "@/components/indicators/activity-indicator";
|
||||
|
||||
type CameraStorage = {
|
||||
[key: string]: {
|
||||
bandwidth: number;
|
||||
usage: number;
|
||||
usage_percent: number;
|
||||
};
|
||||
};
|
||||
|
||||
type StorageMetricsProps = {
|
||||
setLastUpdated: (last: number) => void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user