1
1
import asyncio
2
2
import concurrent .futures
3
+ import datetime
3
4
import json
4
5
import time
5
6
from typing import Any , Dict , List , Optional , Tuple , Union
@@ -62,10 +63,27 @@ def get_frame_from_workflow_output(
62
63
) -> Optional [np .ndarray ]:
63
64
step_output = workflow_output .get (frame_output_key )
64
65
if isinstance (step_output , WorkflowImageData ):
66
+ if (
67
+ step_output .video_metadata
68
+ and step_output .video_metadata .frame_timestamp is not None
69
+ ):
70
+ latency = (
71
+ datetime .datetime .now () - step_output .video_metadata .frame_timestamp
72
+ )
73
+ logger .info ("Processing latency: %ss" , latency .total_seconds ())
65
74
return step_output .numpy_image
66
75
elif isinstance (step_output , dict ):
67
76
for frame_output in step_output .values ():
68
77
if isinstance (frame_output , WorkflowImageData ):
78
+ if (
79
+ frame_output .video_metadata
80
+ and frame_output .video_metadata .frame_timestamp is not None
81
+ ):
82
+ latency = (
83
+ datetime .datetime .now ()
84
+ - frame_output .video_metadata .frame_timestamp
85
+ )
86
+ logger .info ("Processing latency: %ss" , latency .total_seconds ())
69
87
return frame_output .numpy_image
70
88
71
89
@@ -77,8 +95,6 @@ def __init__(
77
95
asyncio_loop : asyncio .AbstractEventLoop ,
78
96
processing_timeout : float ,
79
97
fps_probe_frames : int ,
80
- min_consecutive_on_time : int ,
81
- max_consecutive_timeouts : Optional [int ] = None ,
82
98
webcam_fps : Optional [float ] = None ,
83
99
* args ,
84
100
** kwargs ,
@@ -104,10 +120,6 @@ def __init__(
104
120
self .incoming_stream_fps : Optional [float ] = webcam_fps
105
121
106
122
self ._last_frame : Optional [VideoFrame ] = None
107
- self ._consecutive_timeouts : int = 0
108
- self ._consecutive_on_time : int = 0
109
- self ._max_consecutive_timeouts : Optional [int ] = max_consecutive_timeouts
110
- self ._min_consecutive_on_time : int = min_consecutive_on_time
111
123
112
124
self ._av_logging_set : bool = False
113
125
@@ -146,7 +158,7 @@ async def recv(self):
146
158
147
159
if not await self .to_inference_queue .async_full ():
148
160
await self .to_inference_queue .async_put (frame )
149
- elif not self . _last_frame :
161
+ else :
150
162
await self .to_inference_queue .async_get_nowait ()
151
163
await self .to_inference_queue .async_put_nowait (frame )
152
164
@@ -157,55 +169,22 @@ async def recv(self):
157
169
)
158
170
new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
159
171
self ._last_frame = new_frame
160
-
161
- if self ._max_consecutive_timeouts :
162
- self ._consecutive_on_time += 1
163
- if self ._consecutive_on_time >= self ._min_consecutive_on_time :
164
- self ._consecutive_timeouts = 0
165
172
except asyncio .TimeoutError :
166
- while not await self .to_inference_queue .async_empty ():
167
- await self .to_inference_queue .async_get_nowait ()
168
- if self ._last_frame :
169
- if self ._max_consecutive_timeouts :
170
- self ._consecutive_timeouts += 1
171
- if self ._consecutive_timeouts >= self ._max_consecutive_timeouts :
172
- self ._consecutive_on_time = 0
173
-
174
- workflow_too_slow_message = [
175
- "Workflow is too heavy to process all frames on time..."
176
- ]
173
+ pass
174
+
177
175
if np_frame is None :
178
176
if not self ._last_frame :
179
177
np_frame = overlay_text_on_np_frame (
180
178
frame .to_ndarray (format = "bgr24" ),
181
179
["Inference pipeline is starting..." ],
182
180
)
183
181
new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
184
- elif (
185
- self ._max_consecutive_timeouts
186
- and self ._consecutive_timeouts >= self ._max_consecutive_timeouts
187
- ):
188
- np_frame = overlay_text_on_np_frame (
189
- self ._last_frame .to_ndarray (format = "bgr24" ),
190
- workflow_too_slow_message ,
191
- )
192
- new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
193
182
else :
194
183
new_frame = self ._last_frame
195
184
else :
196
- if (
197
- self ._max_consecutive_timeouts
198
- and self ._consecutive_timeouts >= self ._max_consecutive_timeouts
199
- ):
200
- np_frame = overlay_text_on_np_frame (
201
- self ._last_frame .to_ndarray (format = "bgr24" ),
202
- workflow_too_slow_message ,
203
- )
204
- new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
205
- else :
206
- new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
185
+ new_frame = VideoFrame .from_ndarray (np_frame , format = "bgr24" )
207
186
208
- new_frame .pts = self . _processed
187
+ new_frame .pts = frame . pts
209
188
new_frame .time_base = frame .time_base
210
189
211
190
return new_frame
@@ -312,8 +291,6 @@ async def init_rtc_peer_connection(
312
291
asyncio_loop : asyncio .AbstractEventLoop ,
313
292
processing_timeout : float ,
314
293
fps_probe_frames : int ,
315
- max_consecutive_timeouts : int ,
316
- min_consecutive_on_time : int ,
317
294
webrtc_turn_config : Optional [WebRTCTURNConfig ] = None ,
318
295
webcam_fps : Optional [float ] = None ,
319
296
stream_output : Optional [str ] = None ,
@@ -326,8 +303,6 @@ async def init_rtc_peer_connection(
326
303
webcam_fps = webcam_fps ,
327
304
processing_timeout = processing_timeout ,
328
305
fps_probe_frames = fps_probe_frames ,
329
- max_consecutive_timeouts = max_consecutive_timeouts ,
330
- min_consecutive_on_time = min_consecutive_on_time ,
331
306
)
332
307
333
308
if webrtc_turn_config :
0 commit comments