mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
image size averages
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -11,7 +11,7 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||||
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
<meta name="apple-mobile-web-app-title" content="Multi Roomba Rover" />
|
||||||
<title>Multi Roomba Rover</title>
|
<title>Multi Roomba Rover</title>
|
||||||
<script type="module" crossorigin src="/assets/index-BrK8dCMT.js"></script>
|
<script type="module" crossorigin src="/assets/index-BosVsfhJ.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-Fk2eqSbH.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-Fk2eqSbH.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export function useRoomCameraSnapshots(sourceList = [], options = {}) {
|
|||||||
}, [ids, version]);
|
}, [ids, version]);
|
||||||
const idsRef = useRef([]);
|
const idsRef = useRef([]);
|
||||||
const [connectionNonce, setConnectionNonce] = useState(0);
|
const [connectionNonce, setConnectionNonce] = useState(0);
|
||||||
|
const statsRef = useRef(new Map());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socket) return undefined;
|
if (!socket) return undefined;
|
||||||
@@ -46,6 +47,30 @@ export function useRoomCameraSnapshots(sourceList = [], options = {}) {
|
|||||||
|
|
||||||
const handleFrame = (meta = {}, buffer) => {
|
const handleFrame = (meta = {}, buffer) => {
|
||||||
if (cancelled || !meta.id || !buffer) return;
|
if (cancelled || !meta.id || !buffer) return;
|
||||||
|
const sizeBytes = buffer.byteLength ?? buffer.length ?? 0;
|
||||||
|
const now = Date.now();
|
||||||
|
const prevStats = statsRef.current.get(meta.id) || {
|
||||||
|
count: 0,
|
||||||
|
totalBytes: 0,
|
||||||
|
lastLogAt: 0,
|
||||||
|
};
|
||||||
|
const nextStats = {
|
||||||
|
count: prevStats.count + 1,
|
||||||
|
totalBytes: prevStats.totalBytes + sizeBytes,
|
||||||
|
lastLogAt: prevStats.lastLogAt,
|
||||||
|
};
|
||||||
|
if (!nextStats.lastLogAt || now - nextStats.lastLogAt >= 10000) {
|
||||||
|
const avgBytes = nextStats.count ? nextStats.totalBytes / nextStats.count : 0;
|
||||||
|
console.log(
|
||||||
|
'[roomCamera]',
|
||||||
|
meta.id,
|
||||||
|
`frame=${sizeBytes}B`,
|
||||||
|
`avg=${Math.round(avgBytes)}B`,
|
||||||
|
`count=${nextStats.count}`,
|
||||||
|
);
|
||||||
|
nextStats.lastLogAt = now;
|
||||||
|
}
|
||||||
|
statsRef.current.set(meta.id, nextStats);
|
||||||
const blob = new Blob([buffer], { type: 'image/jpeg' });
|
const blob = new Blob([buffer], { type: 'image/jpeg' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const prevUrl = objectUrls.current.get(meta.id);
|
const prevUrl = objectUrls.current.get(meta.id);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export function useRoverSnapshots(sourceList = [], options = {}) {
|
|||||||
}, [ids, version]);
|
}, [ids, version]);
|
||||||
const idsRef = useRef([]);
|
const idsRef = useRef([]);
|
||||||
const [connectionNonce, setConnectionNonce] = useState(0);
|
const [connectionNonce, setConnectionNonce] = useState(0);
|
||||||
|
const statsRef = useRef(new Map());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!socket) return undefined;
|
if (!socket) return undefined;
|
||||||
@@ -49,6 +50,30 @@ export function useRoverSnapshots(sourceList = [], options = {}) {
|
|||||||
|
|
||||||
const handleFrame = (meta = {}, buffer) => {
|
const handleFrame = (meta = {}, buffer) => {
|
||||||
if (cancelled || !meta.id || !buffer) return;
|
if (cancelled || !meta.id || !buffer) return;
|
||||||
|
const sizeBytes = buffer.byteLength ?? buffer.length ?? 0;
|
||||||
|
const now = Date.now();
|
||||||
|
const prevStats = statsRef.current.get(meta.id) || {
|
||||||
|
count: 0,
|
||||||
|
totalBytes: 0,
|
||||||
|
lastLogAt: 0,
|
||||||
|
};
|
||||||
|
const nextStats = {
|
||||||
|
count: prevStats.count + 1,
|
||||||
|
totalBytes: prevStats.totalBytes + sizeBytes,
|
||||||
|
lastLogAt: prevStats.lastLogAt,
|
||||||
|
};
|
||||||
|
if (!nextStats.lastLogAt || now - nextStats.lastLogAt >= 10000) {
|
||||||
|
const avgBytes = nextStats.count ? nextStats.totalBytes / nextStats.count : 0;
|
||||||
|
console.log(
|
||||||
|
'[roverSnapshot]',
|
||||||
|
meta.id,
|
||||||
|
`frame=${sizeBytes}B`,
|
||||||
|
`avg=${Math.round(avgBytes)}B`,
|
||||||
|
`count=${nextStats.count}`,
|
||||||
|
);
|
||||||
|
nextStats.lastLogAt = now;
|
||||||
|
}
|
||||||
|
statsRef.current.set(meta.id, nextStats);
|
||||||
const blob = new Blob([buffer], { type: 'image/jpeg' });
|
const blob = new Blob([buffer], { type: 'image/jpeg' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const prevUrl = objectUrls.current.get(meta.id);
|
const prevUrl = objectUrls.current.get(meta.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user