|
11 | 11 | from rspy import test, log |
12 | 12 | import time |
13 | 13 | import platform |
| 14 | +import fps_helper |
14 | 15 |
|
15 | 16 | # This test mirrors test-fps.py but forces manual exposure where supported |
16 | | - |
17 | | -global first_frame_seconds |
18 | | - |
19 | | -def measure_fps(sensor, profile, seconds_to_count_frames = 10): |
20 | | - """ |
21 | | - Wait a few seconds to be sure that frames are at steady state after start |
22 | | - Count number of received frames for seconds_to_count_frames seconds and compare actual fps to requested fps |
23 | | - """ |
24 | | - seconds_till_steady_state = 4 |
25 | | - |
26 | | - steady_state = False |
27 | | - first_frame_received = False |
28 | | - frames_received = 0 |
29 | | - first_frame_stopwatch = Stopwatch() |
30 | | - prev_frame_number = 0 |
31 | | - |
32 | | - def frame_cb(frame): |
33 | | - global first_frame_seconds |
34 | | - nonlocal steady_state, frames_received, first_frame_received, prev_frame_number |
35 | | - current_frame_number = frame.get_frame_number() |
36 | | - if not first_frame_received: |
37 | | - first_frame_seconds = first_frame_stopwatch.get_elapsed() |
38 | | - first_frame_received = True |
39 | | - else: |
40 | | - if current_frame_number > prev_frame_number + 1: |
41 | | - log.w( f'Frame drop detected. Current frame number {current_frame_number} previous was {prev_frame_number}' ) |
42 | | - if steady_state: |
43 | | - frames_received += 1 |
44 | | - prev_frame_number = current_frame_number |
45 | | - |
46 | | - sensor.open(profile) |
47 | | - sensor.start(frame_cb) |
48 | | - first_frame_stopwatch.reset() |
49 | | - |
50 | | - time.sleep(seconds_till_steady_state) |
51 | | - |
52 | | - steady_state = True |
53 | | - |
54 | | - time.sleep(seconds_to_count_frames) # Time to count frames |
55 | | - |
56 | | - steady_state = False # Stop counting |
57 | | - |
58 | | - sensor.stop() |
59 | | - sensor.close() |
60 | | - |
61 | | - fps = frames_received / seconds_to_count_frames |
62 | | - return fps |
63 | | - |
| 17 | +# Start depth + color streams and measure frame frequency using sensor API. |
| 18 | +# Verify that actual fps is as requested |
64 | 19 |
|
65 | 20 | def set_exposure_half_frame_time(sensor, requested_fps): |
66 | 21 | """Set sensor exposure to half the frame time for the given requested_fps. |
@@ -144,8 +99,11 @@ def set_exposure_half_frame_time(sensor, requested_fps): |
144 | 99 | else: |
145 | 100 | # set exposure to half frame time for this requested fps if supported |
146 | 101 | exposure_val = set_exposure_half_frame_time(ds, requested_fps) |
147 | | - fps = measure_fps(ds, dp, time_to_test_fps[i]) |
148 | | - log.i("Exposure: {:.1f} [msec], requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(exposure_val/1000, requested_fps, fps, first_frame_seconds)) |
| 102 | + # use shared fps helper which expects a dict of {sensor: [profile]} |
| 103 | + fps_helper.TIME_TO_COUNT_FRAMES = time_to_test_fps[i] |
| 104 | + fps_dict = fps_helper.measure_fps({ds: [dp]}) |
| 105 | + fps = fps_dict.get(dp.stream_name(), 0) |
| 106 | + log.i("Exposure: {:.1f} [msec], requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format((exposure_val or 0)/1000, requested_fps, fps)) |
149 | 107 | delta_Hz = requested_fps * 0.05 # Validation KPI is 5% |
150 | 108 | test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz)) |
151 | 109 | test.finish() |
@@ -188,8 +146,9 @@ def set_exposure_half_frame_time(sensor, requested_fps): |
188 | 146 | else: |
189 | 147 | # set exposure to half frame time for this requested fps if supported |
190 | 148 | exposure_val = set_exposure_half_frame_time(cs, requested_fps) |
191 | | - fps = measure_fps(cs, cp, time_to_test_fps[i]) |
192 | | - log.i("Exposure: {:.1f} [msec], requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]. Time to first frame {:.6f}".format(exposure_val/1000, requested_fps, fps, first_frame_seconds)) |
| 149 | + fps_dict = fps_helper.measure_fps({cs: [cp]}) |
| 150 | + fps = fps_dict.get(cp.stream_name(), 0) |
| 151 | + log.i("Exposure: {:.1f} [msec], requested fps: {:.1f} [Hz], actual fps: {:.1f} [Hz]".format((exposure_val or 0)/1000, requested_fps, fps)) |
193 | 152 | delta_Hz = requested_fps * (0.10 if requested_fps == 5 else 0.05) # Validation KPI is 5% for all non 5 FPS rate |
194 | 153 | test.check(fps <= (requested_fps + delta_Hz) and fps >= (requested_fps - delta_Hz)) |
195 | 154 |
|
|
0 commit comments