image size averages

This commit is contained in:
legop3
2026-01-17 18:35:04 -05:00
parent befcf7ad5a
commit 2975d394b6
4 changed files with 60 additions and 10 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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>
+25
View File
@@ -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);
+25
View File
@@ -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);