mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 09:12:18 +00:00
cctv: live-video panel card — canvas painted from the active camera's video element, 16:9 wrap, gated against the still-image path
This commit is contained in:
1 parent
e02492cfc2
commit
71aa889133
6 files changed
+64
-1
No files matched your search
@@ -164,7 +164,46 @@ export function _renderCctvState(state) {
|
||||
}
|
||||
}
|
||||
|
||||
if (this._cctvFrame) {
|
||||
// Live video: for HLS cameras, paint the active camera's decoded <video>
|
||||
// element onto a canvas each frame (one decoder, two surfaces — the plane
|
||||
// reads the same element). The loop rides through hls.js pipeline resets
|
||||
// (a null element or unchanged currentTime is a skipped frame, not an exit)
|
||||
// and self-stops when the card hides or the feed goes away. The still-image
|
||||
// path below is suppressed while a live feed is showing.
|
||||
const liveIntent = enabled && !!activeCamera?.isVideo;
|
||||
if (this._cctvVideo) {
|
||||
this._cctvVideo.hidden = !liveIntent;
|
||||
if (this._cctvFrame) this._cctvFrame.hidden = liveIntent;
|
||||
this._cctvVideoActive = liveIntent;
|
||||
if (liveIntent && !this._cctvVideoRaf) {
|
||||
const canvas = this._cctvVideo;
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
let lastTime = -1;
|
||||
const paint = () => {
|
||||
if (this.destroyed || !this._cctvVideoActive) {
|
||||
this._cctvVideoRaf = 0;
|
||||
return;
|
||||
}
|
||||
const v = this.cctv.getActiveVideoElement();
|
||||
if (v && v.currentTime !== lastTime) {
|
||||
lastTime = v.currentTime;
|
||||
if (
|
||||
canvas.width !== v.videoWidth ||
|
||||
canvas.height !== v.videoHeight
|
||||
) {
|
||||
canvas.width = v.videoWidth;
|
||||
canvas.height = v.videoHeight;
|
||||
}
|
||||
ctx.drawImage(v, 0, 0);
|
||||
}
|
||||
this._cctvVideoRaf = requestAnimationFrame(paint);
|
||||
};
|
||||
this._cctvVideoRaf = requestAnimationFrame(paint);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._cctvFrame && !liveIntent) {
|
||||
const nextSrc = enabled ? activeCamera?.frameUrl : null;
|
||||
const nextCameraId = enabled ? activeCamera?.id || '' : '';
|
||||
const cameraChanged = this._cctvFrame.dataset.cameraId !== nextCameraId;
|
||||
@@ -183,6 +222,8 @@ export function _renderCctvState(state) {
|
||||
if (!nextSrc) {
|
||||
this._clearCctvFrame();
|
||||
}
|
||||
} else if (liveIntent) {
|
||||
this._clearCctvFrame();
|
||||
}
|
||||
|
||||
this._syncCctvSourceBadge(activeCamera, enabled);
|
||||
|
||||
Reference in new issue
Block a user