envio de dados das cameras

This commit is contained in:
Diego Freitas 2026-03-12 11:01:04 -03:00
parent 6b72fed408
commit 7f39aaecad
2 changed files with 32 additions and 1 deletions

View File

@ -427,7 +427,6 @@ class CameraGal:
# 1) Atualiza modo (não custa caro)
self._maybe_update_mode()
params = self._mode_params(self._op_mode)
self._op_fps = params["fps"]
# 2) Throttle por FPS (só tenta enviar quando "bate o relógio")
@ -435,6 +434,7 @@ class CameraGal:
min_dt = 1.0 / max(0.1, self._op_fps)
if (now - self._last_frame_sent_ts) < min_dt:
return
prev_sent_ts = self._last_frame_sent_ts
self._last_frame_sent_ts = now
# 4) Conexão socket (igual você já faz)
@ -456,15 +456,30 @@ class CameraGal:
size = len(data)
header = struct.pack("!I", size)
# 6) Calcula bitrate real
dt_real = max(0.001, now - prev_sent_ts)
kbps_inst = (size * 8) / dt_real / 1000.0
kbps_ant = float(_camera.get("stream_kbps", 0.0) or 0.0)
kbps_suave = kbps_inst if kbps_ant <= 0 else (kbps_ant * 0.8 + kbps_inst * 0.2)
try:
self._sock.sendall(header + data)
except (BrokenPipeError, ConnectionResetError, OSError) as e:
self._sock_conectado = False
kbps_suave = 0.0
try:
self._sock.close()
except:
pass
self._sock = None
finally:
ContextoGlobalRedis.atualizar_ctx_dict(
ContextoGlobalRedis.CamKey(self.mx_id),
stream_kbps=round(kbps_suave, 1),
fps=params["fps"],
stream_w=params["w"],
stream_h=params["h"],
)
def _get_ipb_bw_util_pct(self) -> float:
ipb = ContextoGlobalRedis.get_modulo(T_Code.Ipb) or {} # ajuste se sua key for diferente

View File

@ -762,6 +762,7 @@ class CameraOak:
min_dt = 1.0 / max(0.1, self._op_fps)
if (now - self._last_frame_sent_ts) < min_dt:
return
prev_sent_ts = self._last_frame_sent_ts
self._last_frame_sent_ts = now
# 4) Conexão socket (igual você já faz)
@ -783,15 +784,30 @@ class CameraOak:
size = len(data)
header = struct.pack("!I", size)
# 6) Calcula bitrate real
dt_real = max(0.001, now - prev_sent_ts)
kbps_inst = (size * 8) / dt_real / 1000.0
kbps_ant = float(_camera.get("stream_kbps", 0.0) or 0.0)
kbps_suave = kbps_inst if kbps_ant <= 0 else (kbps_ant * 0.8 + kbps_inst * 0.2)
try:
self._sock.sendall(header + data)
except (BrokenPipeError, ConnectionResetError, OSError) as e:
self._sock_conectado = False
kbps_suave = 0.0
try:
self._sock.close()
except:
pass
self._sock = None
finally:
ContextoGlobalRedis.atualizar_ctx_dict(
ContextoGlobalRedis.CamKey(self.mx_id),
stream_kbps=round(kbps_suave, 1),
fps=params["fps"],
stream_w=params["w"],
stream_h=params["h"],
)
def _get_ipb_bw_util_pct(self) -> float:
ipb = ContextoGlobalRedis.get_modulo(T_Code.Ipb) or {} # ajuste se sua key for diferente