import React, { useState, useEffect } from "react"; import Admonition from "@theme/Admonition"; import styles from "./styles.module.css"; const ShmCalculator = () => { const [width, setWidth] = useState(1280); const [height, setHeight] = useState(720); const [cameraCount, setCameraCount] = useState(1); const [result, setResult] = useState("26.32MB"); const [singleCameraShm, setSingleCameraShm] = useState("26.32MB"); const [totalShm, setTotalShm] = useState("26.32MB"); const calculate = () => { if (!width || !height || !cameraCount) { setResult("Please enter valid values"); setSingleCameraShm("-"); setTotalShm("-"); return; } // Single camera base SHM calculation (excluding logs) // Formula: (width * height * 1.5 * 20 + 270480) / 1048576 const singleCameraBase = (width * height * 1.5 * 20 + 270480) / 1048576; setSingleCameraShm(`${singleCameraBase.toFixed(2)}mb`); // Total SHM calculation (multiple cameras, including logs) const totalBase = singleCameraBase * cameraCount; const finalResult = totalBase + 40; // Default includes logs +40mb setTotalShm(`${(totalBase + 40).toFixed(2)}mb`); // Format result if (finalResult < 1) { setResult(`${(finalResult * 1024).toFixed(2)}kb`); } else if (finalResult >= 1024) { setResult(`${(finalResult / 1024).toFixed(2)}gb`); } else { setResult(`${finalResult.toFixed(2)}mb`); } }; const formatWithUnit = (value) => { const match = value.match(/^([\d.]+)(mb|kb|gb)$/i); if (match) { return ( <> {match[1]}{match[2]} > ); } return value; }; const applyPreset = (w, h, count) => { setWidth(w); setHeight(h); setCameraCount(count); calculate(); }; useEffect(() => { calculate(); }, [width, height, cameraCount]); return (
Calculate required shared memory (SHM) based on camera resolution and count
Single Camera: {formatWithUnit(singleCameraShm)}
Formula: (width × height × 1.5 × 20 + 270480) ÷ 1048576
{cameraCount > 1 && (Total ({cameraCount} cameras): {formatWithUnit(totalShm)}
)}With Logs: + 40mb