test_sensor_first_frame_delay.py
Go to the documentation of this file.
1 # License: Apache 2.0. See LICENSE file in root directory.
2 # Copyright(c) 2021 Intel Corporation. All Rights Reserved.
3 
4 # test:device L500*
5 # test:device D400*
6 
7 import pyrealsense2 as rs
8 from rspy.stopwatch import Stopwatch
9 from rspy import test, log
10 import time
11 import platform
12 
13 # Start depth + color streams and measure the time from stream opened until first frame arrived using sensor API.
14 # Verify that the time do not exceeds the maximum time allowed
15 # Note - Using Windows Media Foundation to handle power management between USB actions take time (~27 ms)
16 
17 
18 def time_to_first_frame(sensor, profile, max_delay_allowed):
19  """
20  Wait for the first frame for 'max_delay_allowed' + 1 extra second
21  If the frame arrives it will return the seconds it took since open() call
22  If no frame it will return 'max_delay_allowed'
23  """
24  first_frame_time = max_delay_allowed
25  open_call_stopwatch = Stopwatch()
26 
27  def frame_cb(frame):
28  nonlocal first_frame_time, open_call_stopwatch
29  if first_frame_time == max_delay_allowed:
30  first_frame_time = open_call_stopwatch.get_elapsed()
31 
32  open_call_stopwatch.reset()
33  sensor.open(profile)
34  sensor.start(frame_cb)
35 
36  # Wait condition:
37  # 1. first frame did not arrive yet
38  # 2. timeout of 'max_delay_allowed' + 1 extra second reached.
39  while first_frame_time == max_delay_allowed and open_call_stopwatch.get_elapsed() < max_delay_allowed + 1:
40  time.sleep(0.05)
41 
42  sensor.stop()
43  sensor.close()
44 
45  return first_frame_time
46 
47 
48 # The device starts at D0 (Operational) state, allow time for it to get into idle state
49 time.sleep(3)
50 
51 
52 #####################################################################################################
53 test.start("Testing device creation time on " + platform.system() + " OS")
54 device_creation_stopwatch = Stopwatch()
55 dev = test.find_first_device_or_exit()
56 device_creation_time = device_creation_stopwatch.get_elapsed()
57 max_time_for_device_creation = 1.5
58 print("Device creation time is: {:.3f} [sec] max allowed is: {:.1f} [sec] ".format(device_creation_time, max_time_for_device_creation))
59 test.check(device_creation_time < max_time_for_device_creation)
61 
62 
63 # Set maximum delay for first frame according to product line
64 product_line = dev.get_info(rs.camera_info.product_line)
65 if product_line == "D400":
66  max_delay_for_depth_frame = 1.5
67  max_delay_for_color_frame = 1.5
68 elif product_line == "L500":
69  max_delay_for_depth_frame = 2.5 # L515 depth frame has a 1.5 seconds built in delay at the FW side + 1.0 second for LRS
70  max_delay_for_color_frame = 1.5
71 else:
72  log.f( "This test support only D400 + L515 devices" )
73 
74 
75 ds = dev.first_depth_sensor()
76 cs = dev.first_color_sensor()
77 
78 dp = next(p for p in
79  ds.profiles if p.fps() == 30
80  and p.stream_type() == rs.stream.depth
81  and p.format() == rs.format.z16)
82 
83 cp = next(p for p in
84  cs.profiles if p.fps() == 30
85  and p.stream_type() == rs.stream.color
86  and p.format() == rs.format.rgb8)
87 
88 
89 #####################################################################################################
90 test.start("Testing first depth frame delay on " + product_line + " device - "+ platform.system() + " OS")
91 first_depth_frame_delay = time_to_first_frame(ds, dp, max_delay_for_depth_frame)
92 print("Time until first depth frame is: {:.3f} [sec] max allowed is: {:.1f} [sec] ".format(first_depth_frame_delay, max_delay_for_depth_frame))
93 test.check(first_depth_frame_delay < max_delay_for_depth_frame)
95 
96 
97 #####################################################################################################
98 test.start("Testing first color frame delay on " + product_line + " device - "+ platform.system() + " OS")
99 first_color_frame_delay = time_to_first_frame(cs, cp, max_delay_for_color_frame)
100 print("Time until first color frame is: {:.3f} [sec] max allowed is: {:.1f} [sec] ".format(first_color_frame_delay, max_delay_for_color_frame))
101 test.check(first_color_frame_delay < max_delay_for_color_frame)
102 test.finish()
103 
104 
105 #####################################################################################################
106 test.print_results_and_exit()
static std::string print(const transformation &tf)
virtual frame finish(frame f)
void next(auto_any_t cur, type2type< T, C > *)
Definition: foreach.hpp:757
def time_to_first_frame(sensor, profile, max_delay_allowed)


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:50:11