mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-08 12:15:25 +03:00
Show still image when no activity is occurring
This commit is contained in:
parent
d182b856cf
commit
daad5d3cca
@ -6,6 +6,8 @@ type AutoUpdatingCameraImageProps = {
|
|||||||
searchParams?: {};
|
searchParams?: {};
|
||||||
showFps?: boolean;
|
showFps?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
reloadInterval?: number;
|
||||||
|
fitAspect?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const MIN_LOAD_TIMEOUT_MS = 200;
|
const MIN_LOAD_TIMEOUT_MS = 200;
|
||||||
@ -15,6 +17,8 @@ export default function AutoUpdatingCameraImage({
|
|||||||
searchParams = "",
|
searchParams = "",
|
||||||
showFps = true,
|
showFps = true,
|
||||||
className,
|
className,
|
||||||
|
reloadInterval = MIN_LOAD_TIMEOUT_MS,
|
||||||
|
fitAspect,
|
||||||
}: AutoUpdatingCameraImageProps) {
|
}: AutoUpdatingCameraImageProps) {
|
||||||
const [key, setKey] = useState(Date.now());
|
const [key, setKey] = useState(Date.now());
|
||||||
const [fps, setFps] = useState<string>("0");
|
const [fps, setFps] = useState<string>("0");
|
||||||
@ -23,14 +27,14 @@ export default function AutoUpdatingCameraImage({
|
|||||||
const loadTime = Date.now() - key;
|
const loadTime = Date.now() - key;
|
||||||
|
|
||||||
if (showFps) {
|
if (showFps) {
|
||||||
setFps((1000 / Math.max(loadTime, MIN_LOAD_TIMEOUT_MS)).toFixed(1));
|
setFps((1000 / Math.max(loadTime, reloadInterval)).toFixed(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(
|
setTimeout(
|
||||||
() => {
|
() => {
|
||||||
setKey(Date.now());
|
setKey(Date.now());
|
||||||
},
|
},
|
||||||
loadTime > MIN_LOAD_TIMEOUT_MS ? 1 : MIN_LOAD_TIMEOUT_MS
|
loadTime > reloadInterval ? 1 : reloadInterval
|
||||||
);
|
);
|
||||||
}, [key, setFps]);
|
}, [key, setFps]);
|
||||||
|
|
||||||
@ -39,6 +43,7 @@ export default function AutoUpdatingCameraImage({
|
|||||||
<CameraImage
|
<CameraImage
|
||||||
camera={camera}
|
camera={camera}
|
||||||
onload={handleLoad}
|
onload={handleLoad}
|
||||||
|
fitAspect={fitAspect}
|
||||||
searchParams={`cache=${key}&${searchParams}`}
|
searchParams={`cache=${key}&${searchParams}`}
|
||||||
/>
|
/>
|
||||||
{showFps ? <span className="text-xs">Displaying at {fps}fps</span> : null}
|
{showFps ? <span className="text-xs">Displaying at {fps}fps</span> : null}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import ActivityIndicator from "../ui/activity-indicator";
|
|||||||
import { useResizeObserver } from "@/hooks/resize-observer";
|
import { useResizeObserver } from "@/hooks/resize-observer";
|
||||||
|
|
||||||
type CameraImageProps = {
|
type CameraImageProps = {
|
||||||
|
className?: string;
|
||||||
camera: string;
|
camera: string;
|
||||||
onload?: (event: Event) => void;
|
onload?: (event: Event) => void;
|
||||||
searchParams?: {};
|
searchParams?: {};
|
||||||
@ -13,6 +14,7 @@ type CameraImageProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function CameraImage({
|
export default function CameraImage({
|
||||||
|
className,
|
||||||
camera,
|
camera,
|
||||||
onload,
|
onload,
|
||||||
searchParams = "",
|
searchParams = "",
|
||||||
@ -88,11 +90,12 @@ export default function CameraImage({
|
|||||||
<div
|
<div
|
||||||
className={`relative w-full ${
|
className={`relative w-full ${
|
||||||
fitAspect && aspectRatio < fitAspect ? "h-full flex justify-center" : ""
|
fitAspect && aspectRatio < fitAspect ? "h-full flex justify-center" : ""
|
||||||
}`}
|
} ${className}`}
|
||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
>
|
>
|
||||||
{enabled ? (
|
{enabled ? (
|
||||||
<canvas
|
<canvas
|
||||||
|
className="rounded-2xl"
|
||||||
data-testid="cameraimage-canvas"
|
data-testid="cameraimage-canvas"
|
||||||
height={scaledHeight}
|
height={scaledHeight}
|
||||||
ref={canvasRef}
|
ref={canvasRef}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import AutoUpdatingCameraImage from "../camera/AutoUpdatingCameraImage";
|
|||||||
import ActivityIndicator from "../ui/activity-indicator";
|
import ActivityIndicator from "../ui/activity-indicator";
|
||||||
import { Button } from "../ui/button";
|
import { Button } from "../ui/button";
|
||||||
import { LuSettings } from "react-icons/lu";
|
import { LuSettings } from "react-icons/lu";
|
||||||
import { useCallback, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
|
import { Card, CardContent, CardHeader, CardTitle } from "../ui/card";
|
||||||
import { Switch } from "../ui/switch";
|
import { Switch } from "../ui/switch";
|
||||||
import { Label } from "../ui/label";
|
import { Label } from "../ui/label";
|
||||||
@ -15,14 +15,18 @@ import { MdCircle, MdLeakAdd, MdSelectAll } from "react-icons/md";
|
|||||||
import { BsSoundwave } from "react-icons/bs";
|
import { BsSoundwave } from "react-icons/bs";
|
||||||
import Chip from "../Chip";
|
import Chip from "../Chip";
|
||||||
import useCameraActivity from "@/hooks/use-camera-activity";
|
import useCameraActivity from "@/hooks/use-camera-activity";
|
||||||
|
import CameraImage from "../camera/CameraImage";
|
||||||
|
|
||||||
const emptyObject = Object.freeze({});
|
const emptyObject = Object.freeze({});
|
||||||
|
|
||||||
|
type LivePlayerMode = "webrtc" | "mse" | "jsmpeg" | "debug";
|
||||||
|
|
||||||
type LivePlayerProps = {
|
type LivePlayerProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
cameraConfig: CameraConfig;
|
cameraConfig: CameraConfig;
|
||||||
liveMode?: "webrtc" | "mse" | "jsmpeg" | "debug";
|
liveMode?: LivePlayerMode;
|
||||||
liveChips?: boolean;
|
liveChips?: boolean;
|
||||||
|
showStillWithoutActivity?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type Options = { [key: string]: boolean };
|
type Options = { [key: string]: boolean };
|
||||||
@ -32,11 +36,23 @@ export default function LivePlayer({
|
|||||||
cameraConfig,
|
cameraConfig,
|
||||||
liveMode = "mse",
|
liveMode = "mse",
|
||||||
liveChips = false,
|
liveChips = false,
|
||||||
|
showStillWithoutActivity = true,
|
||||||
}: LivePlayerProps) {
|
}: LivePlayerProps) {
|
||||||
// camera activity
|
// camera activity
|
||||||
const { activeMotion, activeAudio, activeTracking } =
|
const { activeMotion, activeAudio, activeTracking } =
|
||||||
useCameraActivity(cameraConfig);
|
useCameraActivity(cameraConfig);
|
||||||
|
|
||||||
|
const [liveReady, setLiveReady] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
if (!liveReady) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activeMotion && !activeTracking) {
|
||||||
|
setLiveReady(false);
|
||||||
|
}
|
||||||
|
}, [activeMotion, activeTracking, liveReady]);
|
||||||
|
|
||||||
// debug view settings
|
// debug view settings
|
||||||
|
|
||||||
const [showSettings, setShowSettings] = useState(false);
|
const [showSettings, setShowSettings] = useState(false);
|
||||||
@ -80,7 +96,13 @@ export default function LivePlayer({
|
|||||||
);
|
);
|
||||||
} else if (liveMode == "mse") {
|
} else if (liveMode == "mse") {
|
||||||
if ("MediaSource" in window || "ManagedMediaSource" in window) {
|
if ("MediaSource" in window || "ManagedMediaSource" in window) {
|
||||||
player = <MSEPlayer className="rounded-2xl" camera={cameraConfig.name} />;
|
player = (
|
||||||
|
<MSEPlayer
|
||||||
|
className="rounded-2xl"
|
||||||
|
camera={cameraConfig.name}
|
||||||
|
onPlaying={() => setLiveReady(true)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
player = (
|
player = (
|
||||||
<div className="w-5xl text-center text-sm">
|
<div className="w-5xl text-center text-sm">
|
||||||
@ -131,18 +153,43 @@ export default function LivePlayer({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`relative flex justify-center ${className}`}>
|
<div className={`relative flex justify-center ${className}`}>
|
||||||
{player}
|
{(showStillWithoutActivity == false || activeMotion || activeTracking) &&
|
||||||
|
player}
|
||||||
|
|
||||||
|
{showStillWithoutActivity && !liveReady && (
|
||||||
|
<div className="absolute left-0 top-0 right-0 bottom-0">
|
||||||
|
<AutoUpdatingCameraImage
|
||||||
|
className="w-full h-full"
|
||||||
|
camera={cameraConfig.name}
|
||||||
|
showFps={false}
|
||||||
|
reloadInterval={30000}
|
||||||
|
fitAspect={
|
||||||
|
cameraConfig.detect.width / cameraConfig.detect.height > 2 ||
|
||||||
|
cameraConfig.detect.width / cameraConfig.detect.height < 1
|
||||||
|
? undefined
|
||||||
|
: 16 / 9
|
||||||
|
}
|
||||||
|
searchParams={`cache=${123}`}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{liveChips && (
|
||||||
<div className="absolute flex left-2 top-2 gap-2">
|
<div className="absolute flex left-2 top-2 gap-2">
|
||||||
<Chip className="bg-gray-500 bg-gradient-to-br">
|
<Chip className="bg-gray-500 bg-gradient-to-br">
|
||||||
<MdLeakAdd
|
<MdLeakAdd
|
||||||
className={`w-4 h-4 ${activeMotion ? "text-motion" : "text-white"}`}
|
className={`w-4 h-4 ${
|
||||||
|
activeMotion ? "text-motion" : "text-white"
|
||||||
|
}`}
|
||||||
/>
|
/>
|
||||||
<div className="ml-1 capitalize text-white text-xs">Motion</div>
|
<div className="ml-1 capitalize text-white text-xs">Motion</div>
|
||||||
</Chip>
|
</Chip>
|
||||||
{cameraConfig.audio.enabled_in_config && (
|
{cameraConfig.audio.enabled_in_config && (
|
||||||
<Chip className="bg-gray-500 bg-gradient-to-br">
|
<Chip className="bg-gray-500 bg-gradient-to-br">
|
||||||
<BsSoundwave
|
<BsSoundwave
|
||||||
className={`w-4 h-4 ${activeAudio ? "text-audio" : "text-white"}`}
|
className={`w-4 h-4 ${
|
||||||
|
activeAudio ? "text-audio" : "text-white"
|
||||||
|
}`}
|
||||||
/>
|
/>
|
||||||
<div className="ml-1 capitalize text-white text-xs">Sound</div>
|
<div className="ml-1 capitalize text-white text-xs">Sound</div>
|
||||||
</Chip>
|
</Chip>
|
||||||
@ -156,6 +203,7 @@ export default function LivePlayer({
|
|||||||
<div className="ml-1 capitalize text-white text-xs">Tracking</div>
|
<div className="ml-1 capitalize text-white text-xs">Tracking</div>
|
||||||
</Chip>
|
</Chip>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
<Chip className="absolute right-2 top-2 bg-gray-500 bg-gradient-to-br">
|
<Chip className="absolute right-2 top-2 bg-gray-500 bg-gradient-to-br">
|
||||||
<MdCircle className="w-2 h-2 text-danger" />
|
<MdCircle className="w-2 h-2 text-danger" />
|
||||||
<div className="ml-1 capitalize text-white text-xs">
|
<div className="ml-1 capitalize text-white text-xs">
|
||||||
|
|||||||
@ -4,9 +4,10 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|||||||
type MSEPlayerProps = {
|
type MSEPlayerProps = {
|
||||||
camera: string;
|
camera: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
onPlaying?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function MSEPlayer({ camera, className }: MSEPlayerProps) {
|
function MSEPlayer({ camera, className, onPlaying }: MSEPlayerProps) {
|
||||||
let connectTS: number = 0;
|
let connectTS: number = 0;
|
||||||
|
|
||||||
const RECONNECT_TIMEOUT: number = 30000;
|
const RECONNECT_TIMEOUT: number = 30000;
|
||||||
@ -250,6 +251,7 @@ function MSEPlayer({ camera, className }: MSEPlayerProps) {
|
|||||||
className={className}
|
className={className}
|
||||||
playsInline
|
playsInline
|
||||||
preload="auto"
|
preload="auto"
|
||||||
|
onLoadedData={onPlaying}
|
||||||
muted
|
muted
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user