Improved corrupt frame handling

master
Lauri Võsandi 6 months ago
parent 3d1aa220dd
commit 4814030936
  1. 30
      camdetect.py

@ -376,26 +376,28 @@ async def download(resp, queue):
blob = buf + data[:marker+2]
# Parse DCT coefficients
dct = loads(blob)
now = datetime.utcnow()
gauge_last_frame.labels("download").set(now.timestamp())
try:
# Convert Y component to 16 bit for easier handling
queue.put_nowait((
now,
blob,
dct,
generate_thumbnail(dct)))
except asyncio.QueueFull:
counter_dropped_frames.labels("download").inc()
gauge_queue_frames.labels("download").set(queue.qsize())
dct = loads(blob)
except RuntimeError:
counter_frames.labels("corrupted").inc()
else:
now = datetime.utcnow()
gauge_last_frame.labels("download").set(now.timestamp())
try:
queue.put_nowait((
now,
blob,
dct,
generate_thumbnail(dct)))
except asyncio.QueueFull:
counter_dropped_frames.labels("download").inc()
gauge_queue_frames.labels("download").set(queue.qsize())
data = data[marker+2:]
buf = b""
counter_receive_frames.inc()
# seek begin
marker = data.find(b"\xff\xd8")
marker = data.rfind(b"\xff\xd8")
if marker >= 0:
buf = data[marker:]
else:

Loading…
Cancel
Save