|
11 | 11 | from rspy import test, log |
12 | 12 | import time |
13 | 13 | import platform |
| 14 | +import fps_helper |
14 | 15 |
|
15 | 16 | # Start depth + color streams and measure frame frequency using sensor API. |
16 | 17 | # Verify that actual fps is as requested |
17 | 18 |
|
18 | | -global first_frame_seconds |
19 | | - |
20 | | -def measure_fps(sensor, profile, seconds_to_count_frames = 10): |
21 | | - """ |
22 | | - Wait a few seconds to be sure that frames are at steady state after start |
23 | | - Count number of received frames for seconds_to_count_frames seconds and compare actual fps to requested fps |
24 | | - """ |
25 | | - seconds_till_steady_state = 4 |
26 | | - |
27 | | - steady_state = False |
28 | | - first_frame_received = False |
29 | | - frames_received = 0 |
30 | | - first_frame_stopwatch = Stopwatch() |
31 | | - prev_frame_number = 0 |
32 | | - |
33 | | - def frame_cb(frame): |
34 | | - global first_frame_seconds |
35 | | - nonlocal steady_state, frames_received, first_frame_received, prev_frame_number |
36 | | - current_frame_number = frame.get_frame_number() |
37 | | - if not first_frame_received: |
38 | | - first_frame_seconds = first_frame_stopwatch.get_elapsed() |
39 | | - first_frame_received = True |
40 | | - else: |
41 | | - if current_frame_number > prev_frame_number + 1: |
42 | | - log.w( f'Frame drop detected. Current frame number {current_frame_number} previous was {prev_frame_number}' ) |
43 | | - if steady_state: |
44 | | - frames_received += 1 |
45 | | - prev_frame_number = current_frame_number |
46 | | - |
47 | | - sensor.open(profile) |
48 | | - sensor.start(frame_cb) |
49 | | - first_frame_stopwatch.reset() |
50 | | - |
51 | | - time.sleep(seconds_till_steady_state) |
52 | | - |
53 | | - steady_state = True |
54 | | - |
55 | | - time.sleep(seconds_to_count_frames) # Time to count frames |
56 | | - |
57 | | - steady_state = False # Stop counting |
58 | | - |
59 | | - sensor.stop() |
60 | | - sensor.close() |
61 | | - |
62 | | - fps = frames_received / seconds_to_count_frames |
63 | | - return fps |
64 | | - |
65 | | - |
66 | 19 | delta_Hz = 1 |
67 | 20 | tested_fps = [5, 6, 15, 30, 60, 90] |
68 | 21 | time_to_test_fps = [25, 20, 13, 10, 5, 4] |
@@ -96,8 +49,10 @@ def frame_cb(frame): |
96 | 49 | except StopIteration: |
97 | 50 | log.i("Requested fps: {:.1f} [Hz], not supported".format(requested_fps)) |
98 | 51 | else: |
99 | | - fps = measure_fps(ds, dp, time_to_test_fps[i]) |
100 | | - log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(requested_fps, fps, first_frame_seconds)) |
| 52 | + fps_helper.TIME_TO_COUNT_FRAMES = time_to_test_fps[i] |
| 53 | + fps_dict = fps_helper.measure_fps({ds: [dp]}) |
| 54 | + fps = fps_dict.get(dp.stream_name(), 0) |
| 55 | + log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format(requested_fps, fps)) |
101 | 56 | delta_Hz = requested_fps * 0.05 # Validation KPI is 5% |
102 | 57 | test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz)) |
103 | 58 | test.finish() |
@@ -133,8 +88,10 @@ def frame_cb(frame): |
133 | 88 | except StopIteration: |
134 | 89 | log.i("Requested fps: {:.1f} [Hz], not supported".format(requested_fps)) |
135 | 90 | else: |
136 | | - fps = measure_fps(cs, cp, time_to_test_fps[i]) |
137 | | - log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(requested_fps, fps, first_frame_seconds)) |
| 91 | + fps_helper.TIME_TO_COUNT_FRAMES = time_to_test_fps[i] |
| 92 | + fps_dict = fps_helper.measure_fps({cs: [cp]}) |
| 93 | + fps = fps_dict.get(cp.stream_name(), 0) |
| 94 | + log.i("Requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format(requested_fps, fps)) |
138 | 95 | delta_Hz = requested_fps * (0.10 if requested_fps == 5 else 0.05) # Validation KPI is 5% for all non 5 FPS rate |
139 | 96 | test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz)) |
140 | 97 |
|
|
0 commit comments