Skip to content

Commit e85af30

Browse files
committed
Add more timestamp functions
Allow getting the three different timestamp values from a frame, as well as enabling the global timestamp feature. Topic: timestamp-functions
1 parent d28b0aa commit e85af30

4 files changed

Lines changed: 90 additions & 0 deletions

File tree

src/device.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,20 @@ impl Device {
251251
}
252252
Ok(())
253253
}
254+
255+
/// Check if the device supports global timestamp
256+
pub fn is_global_timestamp_supported(&self) -> Result<bool, OrbbecError> {
257+
self.inner
258+
.is_global_timestamp_supported()
259+
.map_err(OrbbecError::from)
260+
}
261+
262+
/// Enable or disable global timestamp
263+
pub fn enable_global_timestamp(&self, enabled: bool) -> Result<(), OrbbecError> {
264+
self.inner
265+
.enable_global_timestamp(enabled)
266+
.map_err(OrbbecError::from)
267+
}
254268
}
255269

256270
/// A list of Orbbec devices available

src/frame.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,25 @@ pub trait Frame: From<OBFrame> + AsRef<OBFrame> {}
88
macro_rules! impl_video_frame {
99
($t:ident) => {
1010
impl $t {
11+
/// Get the device timestamp of the video frame
12+
pub fn timestamp_us(&self) -> u64 {
13+
self.inner.get_timestamp_us().unwrap()
14+
}
15+
16+
/// Get the system timestamp of the video frame
17+
pub fn system_timestamp_us(&self) -> Result<u64, OrbbecError> {
18+
self.inner
19+
.get_system_timestamp_us()
20+
.map_err(OrbbecError::from)
21+
}
22+
23+
/// Get the global timestamp of the video frame
24+
pub fn global_timestamp_us(&self) -> Result<u64, OrbbecError> {
25+
self.inner
26+
.get_global_timestamp_us()
27+
.map_err(OrbbecError::from)
28+
}
29+
1130
/// Get the raw data of the video frame
1231
pub fn raw_data(&self) -> &[u8] {
1332
// Unwrap is safe here because internal pointer is guaranteed to be valid

src/sys/device.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,27 @@ impl OBDevice {
261261
Ok(value)
262262
}
263263

264+
pub fn is_global_timestamp_supported(&self) -> Result<bool, OBError> {
265+
let mut err_ptr = std::ptr::null_mut();
266+
267+
let supported =
268+
unsafe { orb::ob_device_is_global_timestamp_supported(self.inner, &mut err_ptr) };
269+
270+
OBError::consume(err_ptr)?;
271+
272+
Ok(supported)
273+
}
274+
275+
pub fn enable_global_timestamp(&self, enabled: bool) -> Result<(), OBError> {
276+
let mut err_ptr = std::ptr::null_mut();
277+
278+
unsafe { orb::ob_device_enable_global_timestamp(self.inner, enabled, &mut err_ptr) };
279+
280+
OBError::consume(err_ptr)?;
281+
282+
Ok(())
283+
}
284+
264285
/// Load the device preset
265286
/// After loading the preset, the settings in the preset will set to the device immediately. Therefore, it is recommended to re-read the device settings to update the user program temporarily.
266287
pub fn load_preset(&self, preset_name: &CStr) -> Result<(), OBError> {

src/sys/frame.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,42 @@ impl OBFrame {
1818
self.inner
1919
}
2020

21+
/// Get the frame timestamp (also known as device timestamp, hardware timestamp) of the frame in microseconds.
22+
/// The hardware timestamp is the time point when the frame was captured by the device (Typically in the mid-exposure, unless otherwise stated), on device clock domain.
23+
pub fn get_timestamp_us(&self) -> Result<u64, OBError> {
24+
let mut err_ptr = std::ptr::null_mut();
25+
26+
let timestamp = unsafe { orb::ob_frame_get_timestamp_us(self.inner, &mut err_ptr) };
27+
28+
OBError::consume(err_ptr)?;
29+
30+
Ok(timestamp)
31+
}
32+
33+
/// Get the system timestamp of the frame in microseconds.
34+
/// The system timestamp is the time point when the frame was received by the host, on host clock domain.
35+
pub fn get_system_timestamp_us(&self) -> Result<u64, OBError> {
36+
let mut err_ptr = std::ptr::null_mut();
37+
38+
let timestamp = unsafe { orb::ob_frame_get_system_timestamp_us(self.inner, &mut err_ptr) };
39+
40+
OBError::consume(err_ptr)?;
41+
42+
Ok(timestamp)
43+
}
44+
45+
/// Get the global timestamp of the frame in microseconds.
46+
/// The global timestamp is the time point when the frame was captured by the device, and has been converted to the host clock domain. The conversion process base on the frame timestamp and can eliminate the timer drift of the device
47+
pub fn get_global_timestamp_us(&self) -> Result<u64, OBError> {
48+
let mut err_ptr = std::ptr::null_mut();
49+
50+
let timestamp = unsafe { orb::ob_frame_get_global_timestamp_us(self.inner, &mut err_ptr) };
51+
52+
OBError::consume(err_ptr)?;
53+
54+
Ok(timestamp)
55+
}
56+
2157
/// Get the data buffer of a frame
2258
pub fn get_data(&self) -> Result<&[u8], OBError> {
2359
let mut err_ptr = std::ptr::null_mut();

0 commit comments

Comments
 (0)