Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d500 devices - hw ts from capture stats #13033

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ds/d400/d400-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ namespace librealsense

void d400_color::register_metadata(const synthetic_sensor& color_ep) const
{
color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_uvc_header_parser(&platform::uvc_header::timestamp));

if (_separate_color)
{
auto md_prop_offset = metadata_raw_mode_offset +
Expand Down
6 changes: 6 additions & 0 deletions src/ds/d500/d500-color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ namespace librealsense
color_ep.register_metadata(RS2_FRAME_METADATA_AUTO_EXPOSURE, make_attribute_parser(&md_rgb_control::ae_mode, md_rgb_control_attributes::ae_mode_attribute, md_prop_offset,
[](rs2_metadata_type param) { return (param != 1); })); // OFF value via UVC is 1 (ON is 8)

md_prop_offset = metadata_raw_mode_offset +
offsetof(md_rgb_mode, rgb_mode) +
offsetof(md_rgb_normal_mode, intel_capture_stats);

color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_attribute_parser(&md_capture_stats::hw_timestamp, md_capture_stat_attributes::hw_timestamp_attribute, md_prop_offset));
Copy link
Collaborator

@Nir-Az Nir-Az Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, before we merge, 1 question
why only color? IMO D500 FW will set this for all non IMU streams
Please make sure with Xuetao

Can you make sure with a drop from HKR that this is enabled?
Merging this will cause no timetag right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we also need to change sensor TS to be the new HW TS - Sensor timestamp from MD which is 1/2 of the exposure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Nir - this is for merging to dev branch. I will also do the change for depth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regarding the sensor ts - this is the only one that remains as uvc header's ts, so I'd rather let it as is - do you agree?
Moreover, I need this in my test - see in this PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On D400 and on D500 until now, uvc header timestamp was acctually the hw timestamp, fw set it to the time right after it grabbed the frame, and sensor ts reduced half the exposure so it was actually the sensor time stamp.
Now that FW will set the uvc header as the time the UVC message is constructed (could be much after the readout, reducing the exposure time has no meaning
This is why it needs to change to hw_timestamp - half the exposure (sensor timestamp in MD)
Please try to get more info from Evgeni on Sunday if needed


_ds_color_common->register_metadata();
}

Expand Down
1 change: 0 additions & 1 deletion src/ds/ds-color-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ namespace librealsense

void ds_color_common::register_metadata()
{
_color_ep.register_metadata(RS2_FRAME_METADATA_FRAME_TIMESTAMP, make_uvc_header_parser(&platform::uvc_header::timestamp));
_color_ep.register_metadata(RS2_FRAME_METADATA_ACTUAL_FPS, std::make_shared<ds_md_attribute_actual_fps>());

// attributes of md_capture_timing
Expand Down
3 changes: 2 additions & 1 deletion src/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace librealsense
zoom_factor_attribute = (1u << 8),
scene_mode_attribute = (1u << 9),
sensor_framerate_attribute = (1u << 10),
hw_timestamp_attribute = (1u << 11)
};

/**\brief md_depth_control_attributes - bit mask to find active attributes,
Expand Down Expand Up @@ -384,7 +385,7 @@ namespace librealsense
{
md_header header;
uint32_t flags;
uint32_t reserved;
uint32_t hw_timestamp;
uint64_t exposure_time;
uint64_t exposure_compensation_flags;
int32_t exposure_compensation_value;
Expand Down
57 changes: 57 additions & 0 deletions unit-tests/live/d500/test-hw-timestamp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) 2024 Intel Corporation. All Rights Reserved.

# test:donotrun
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should enable the test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test cannot be enabled right now, because we have no device that supports it in our CI, and this would fail it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, then maybe add a comment explaining why the test is disabled and when it should be enabled


import pyrealsense2 as rs
from rspy import test
import time


dev = test.find_first_device_or_exit()
depth_sensor = dev.first_depth_sensor()
is_global_time_enabled_orig = False
fps = 30


def check_hw_ts_right_before_sensor_ts(frame):
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 = sensor_ts - hw_ts
test.check((1 / fps * 10 ^ 6) > delta > 0)


#############################################################################################
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 hw timestamp and compare it to uvc header"):
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(2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check that we get into the CB at least once

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()
Loading