forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR IntelRealSense#13091 from remibettan: test-for-sensor-ts-vs-frame-s
test added for checking sensor timestamp and frame timestamp metadata values
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# License: Apache 2.0. See LICENSE file in root directory. | ||
# Copyright(c) 2024 Intel Corporation. All Rights Reserved. | ||
|
||
# test:device D400* | ||
|
||
import pyrealsense2 as rs | ||
from rspy import test | ||
import time | ||
|
||
dev = test.find_first_device_or_exit() | ||
depth_sensor = dev.first_depth_sensor() | ||
depth_exposure = depth_sensor.get_option(rs.option.exposure) | ||
is_global_time_enabled_orig = False | ||
fps = 30 | ||
has_at_least_one_frame_arrived = False | ||
|
||
|
||
def check_hw_ts_right_before_sensor_ts(frame): | ||
global has_at_least_one_frame_arrived, depth_exposure | ||
has_at_least_one_frame_arrived = True | ||
frame_ts_supported = frame.supports_frame_metadata(rs.frame_metadata_value.frame_timestamp) | ||
sensor_ts_supported = frame.supports_frame_metadata(rs.frame_metadata_value.sensor_timestamp) | ||
test.check(frame_ts_supported and sensor_ts_supported) | ||
hw_ts = frame.get_frame_metadata(rs.frame_metadata_value.frame_timestamp) | ||
sensor_ts = frame.get_frame_metadata(rs.frame_metadata_value.sensor_timestamp) | ||
delta = hw_ts - sensor_ts | ||
time_between_frames = 1/fps *1000000 | ||
if not test.check_between(delta, min=0, max=time_between_frames): | ||
print("hw_ts = " + repr(hw_ts) + ", sensor_ts = " + repr(sensor_ts) + ", delta = " + repr(delta)) | ||
print("time between frames = " + repr(time_between_frames)) | ||
|
||
|
||
############################################################################################# | ||
with test.closure("Set Depth stream time domain to HW"): | ||
is_global_time_enabled_orig = depth_sensor.get_option(rs.option.global_time_enabled) | ||
if is_global_time_enabled_orig: | ||
depth_sensor.set_option(rs.option.global_time_enabled, 0) | ||
test.check_equal(int(depth_sensor.get_option(rs.option.global_time_enabled)), 0) | ||
|
||
############################################################################################# | ||
with test.closure("Get frame timestamp and compare it to sensor timestamp"): | ||
depth_profile = next(p for p in | ||
depth_sensor.profiles if p.fps() == fps | ||
and p.stream_type() == rs.stream.depth | ||
and p.format() == rs.format.z16 | ||
and p.as_video_stream_profile().width() == 1280 | ||
and p.as_video_stream_profile().height() == 720) | ||
|
||
depth_sensor.open(depth_profile) | ||
depth_sensor.start(check_hw_ts_right_before_sensor_ts) | ||
time.sleep(1) | ||
test.check(has_at_least_one_frame_arrived) | ||
depth_sensor.stop() | ||
depth_sensor.close() | ||
|
||
############################################################################################# | ||
with test.closure("Restore original time domain"): | ||
if is_global_time_enabled_orig: | ||
depth_sensor.set_option(rs.option.global_time_enabled, 1) | ||
test.check_equal(int(depth_sensor.get_option(rs.option.global_time_enabled)), 1) | ||
|
||
############################################################################################# | ||
|
||
test.print_results_and_exit() |