Add desired frame interval argument for /bypass endpoint
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone Build is passing
				
			This commit is contained in:
		
							
								
								
									
										10
									
								
								camdetect.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								camdetect.py
									
									
									
									
									
								
							| @@ -17,6 +17,7 @@ from prometheus_client import Counter, Gauge | ||||
| from sanic import Sanic, response | ||||
| from sanic.response import stream | ||||
| from sanic_prometheus import monitor | ||||
| from time import time | ||||
|  | ||||
| _, url = sys.argv | ||||
|  | ||||
| @@ -375,9 +376,16 @@ app = Sanic("camdetect") | ||||
|  | ||||
| @app.route("/bypass") | ||||
| 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): | ||||
|         ts = 0 | ||||
|         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 | ||||
|             await response.write(data) | ||||
|             counter_tx_bytes.inc(len(data)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user