Server Push 0.3

Server
ahmedmujtaba-gif 2026-04-16 18:47:34 +05:00
parent 7eb227d7b2
commit a8276a1b25
1 changed files with 26 additions and 8 deletions

View File

@ -21,7 +21,7 @@ PASSWORD = os.getenv("password")
# Dynamically find all camera_ip_N variables in environment
CAMERA_IPS = []
for i in range(1, 11): # Supports up to 10 cameras
for i in range(1, 101): # Supports up to 100 cameras
ip = os.getenv(f"camera_ip_{i}")
if ip and ip.strip():
CAMERA_IPS.append(ip.strip())
@ -223,13 +223,31 @@ def _update_grid_frame():
time.sleep(0.1); continue
n = len(frames)
if n == 1: grid = frames[0]
elif n == 2: grid = np.hstack(frames)
if n == 0:
time.sleep(0.1); continue
# Calculate grid dimensions (rows/cols)
cols = int(np.ceil(np.sqrt(n)))
rows = int(np.ceil(n / cols))
# Determine cell size
# Use 320x240 for large grids to prevent the output frame from being too massive
cell_w, cell_h = 320, 240
if n <= 1: cell_w, cell_h = 640, 480
elif n <= 4: cell_w, cell_h = 480, 360
grid_rows = []
for r in range(rows):
row_items = []
for c in range(cols):
idx = r * cols + c
if idx < n:
row_items.append(cv2.resize(frames[idx], (cell_w, cell_h)))
else:
row1 = np.hstack(frames[:2])
if n == 3: row2 = np.hstack([frames[2], np.zeros_like(frames[0])])
else: row2 = np.hstack(frames[2:4])
grid = np.vstack([row1, row2])
row_items.append(np.zeros((cell_h, cell_w, 3), dtype=np.uint8))
grid_rows.append(np.hstack(row_items))
grid = np.vstack(grid_rows)
with lock:
state["grid_frame"] = grid