1+ import time
12import platform
23import numpy as np
34import pyray as rl
103104 }
104105 """
105106
107+ times = {}
108+
106109
107110class CameraView (Widget ):
108111 def __init__ (self , name : str , stream_type : VisionStreamType ):
@@ -225,13 +228,27 @@ def _calc_frame_matrix(self, rect: rl.Rectangle) -> np.ndarray:
225228 ])
226229
227230 def _render (self , rect : rl .Rectangle ):
231+ def tlog (uid ):
232+ nonlocal t
233+ now = time .monotonic ()
234+ if uid not in times :
235+ times [uid ] = [now - t ]
236+ else :
237+ times [uid ].append (now - t )
238+ t = now
239+
240+ t = time .monotonic ()
228241 if self ._switching :
229242 self ._handle_switch ()
230243
244+ tlog ("switch" )
245+
231246 if not self ._ensure_connection ():
232247 self ._draw_placeholder (rect )
233248 return
234249
250+ tlog ("connect" )
251+
235252 # Try to get a new buffer without blocking
236253 buffer = self .client .recv (timeout_ms = 0 )
237254 if buffer :
@@ -240,35 +257,47 @@ def _render(self, rect: rl.Rectangle):
240257 elif not self .client .is_connected ():
241258 # ensure we clear the displayed frame when the connection is lost
242259 self .frame = None
243-
244- if not self .frame :
245- self ._draw_placeholder (rect )
246- return
247-
248- transform = self ._calc_frame_matrix (rect )
249- src_rect = rl .Rectangle (0 , 0 , float (self .frame .width ), float (self .frame .height ))
250- # Flip driver camera horizontally
251- if self ._stream_type == VisionStreamType .VISION_STREAM_DRIVER :
252- src_rect .width = - src_rect .width
253-
254- # Calculate scale
255- scale_x = rect .width * transform [0 , 0 ] # zx
256- scale_y = rect .height * transform [1 , 1 ] # zy
257-
258- # Calculate base position (centered)
259- x_offset = rect .x + (rect .width - scale_x ) / 2
260- y_offset = rect .y + (rect .height - scale_y ) / 2
261-
262- x_offset += transform [0 , 2 ] * rect .width / 2
263- y_offset += transform [1 , 2 ] * rect .height / 2
264-
265- dst_rect = rl .Rectangle (x_offset , y_offset , scale_x , scale_y )
266-
267- # Render with appropriate method
268- if TICI :
269- self ._render_egl (src_rect , dst_rect )
270- else :
271- self ._render_textures (src_rect , dst_rect )
260+ #
261+ # if not self.frame:
262+ # self._draw_placeholder(rect)
263+ # return
264+ #
265+ # tlog("recv")
266+ #
267+ # transform = self._calc_frame_matrix(rect)
268+ # src_rect = rl.Rectangle(0, 0, float(self.frame.width), float(self.frame.height))
269+ # # Flip driver camera horizontally
270+ # if self._stream_type == VisionStreamType.VISION_STREAM_DRIVER:
271+ # src_rect.width = -src_rect.width
272+ #
273+ # # Calculate scale
274+ # scale_x = rect.width * transform[0, 0] # zx
275+ # scale_y = rect.height * transform[1, 1] # zy
276+ #
277+ # # Calculate base position (centered)
278+ # x_offset = rect.x + (rect.width - scale_x) / 2
279+ # y_offset = rect.y + (rect.height - scale_y) / 2
280+ #
281+ # x_offset += transform[0, 2] * rect.width / 2
282+ # y_offset += transform[1, 2] * rect.height / 2
283+ #
284+ # dst_rect = rl.Rectangle(x_offset, y_offset, scale_x, scale_y)
285+ #
286+ # tlog("calc rects")
287+ #
288+ # # Render with appropriate method
289+ # if TICI:
290+ # self._render_egl(src_rect, dst_rect)
291+ # else:
292+ # self._render_textures(src_rect, dst_rect)
293+ #
294+ # tlog("render")
295+
296+ print ("*** CameraView timings ***" )
297+ for uid , tlist in times .items ():
298+ max_time = max (tlist ) * 1000
299+ avg_time = sum (tlist ) / len (tlist ) * 1000
300+ print (f" { uid } : max { max_time :.2f} ms, avg { avg_time :.2f} ms over { len (tlist )} calls" )
272301
273302 def _draw_placeholder (self , rect : rl .Rectangle ):
274303 if self ._placeholder_color :
@@ -342,6 +371,7 @@ def _ensure_connection(self) -> bool:
342371
343372 if not self .client .connect (False ) or not self .client .num_buffers :
344373 return False
374+ return False
345375
346376 cloudlog .debug (f"Connected to { self ._name } stream: { self ._stream_type } , buffers: { self .client .num_buffers } " )
347377 self ._initialize_textures ()
0 commit comments