Add desired frame interval argument for `/bypass` endpoint
continuous-integration/drone Build is passing Details

This commit is contained in:
Lauri Võsandi 2022-02-27 13:35:03 +02:00 committed by Lauri Võsandi
parent 8921c6112d
commit a7158d7580
1 changed files with 9 additions and 1 deletions

View File

@ -17,6 +17,7 @@ from prometheus_client import Counter, Gauge
from sanic import Sanic, response from sanic import Sanic, response
from sanic.response import stream from sanic.response import stream
from sanic_prometheus import monitor from sanic_prometheus import monitor
from time import time
_, url = sys.argv _, url = sys.argv
@ -375,9 +376,16 @@ app = Sanic("camdetect")
@app.route("/bypass") @app.route("/bypass")
async def bypass_stream_wrapper(request): async def bypass_stream_wrapper(request):
# Desired frame interval, by default 500ms
interval = float(request.args.get("interval", 500)) / 1000.0
async def stream_camera(response): async def stream_camera(response):
ts = 0
while True: while True:
await app.ctx.event_frame.wait() while True:
await app.ctx.event_frame.wait()
if time() > ts + interval:
break
ts = time()
data = CHUNK_BOUNDARY + app.ctx.last_frame data = CHUNK_BOUNDARY + app.ctx.last_frame
await response.write(data) await response.write(data)
counter_tx_bytes.inc(len(data)) counter_tx_bytes.inc(len(data))