Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ impl Device {
}
Ok(())
}

/// Check if the device supports global timestamp
pub fn is_global_timestamp_supported(&self) -> Result<bool, OrbbecError> {
self.inner
.is_global_timestamp_supported()
.map_err(OrbbecError::from)
}

/// Enable or disable global timestamp
pub fn enable_global_timestamp(&self, enabled: bool) -> Result<(), OrbbecError> {
self.inner
.enable_global_timestamp(enabled)
.map_err(OrbbecError::from)
}
}

/// A list of Orbbec devices available
Expand Down
19 changes: 19 additions & 0 deletions src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ pub trait Frame: From<OBFrame> + AsRef<OBFrame> {}
macro_rules! impl_video_frame {
($t:ident) => {
impl $t {
/// Get the device timestamp of the video frame
pub fn timestamp_us(&self) -> u64 {
self.inner.get_timestamp_us().unwrap()
}

/// Get the system timestamp of the video frame
pub fn system_timestamp_us(&self) -> Result<u64, OrbbecError> {
self.inner
.get_system_timestamp_us()
.map_err(OrbbecError::from)
}

/// Get the global timestamp of the video frame
pub fn global_timestamp_us(&self) -> Result<u64, OrbbecError> {
self.inner
.get_global_timestamp_us()
.map_err(OrbbecError::from)
}

/// Get the raw data of the video frame
pub fn raw_data(&self) -> &[u8] {
// Unwrap is safe here because internal pointer is guaranteed to be valid
Expand Down
21 changes: 21 additions & 0 deletions src/sys/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ impl OBDevice {
Ok(value)
}

pub fn is_global_timestamp_supported(&self) -> Result<bool, OBError> {
let mut err_ptr = std::ptr::null_mut();

let supported =
unsafe { orb::ob_device_is_global_timestamp_supported(self.inner, &mut err_ptr) };

OBError::consume(err_ptr)?;

Ok(supported)
}

pub fn enable_global_timestamp(&self, enabled: bool) -> Result<(), OBError> {
let mut err_ptr = std::ptr::null_mut();

unsafe { orb::ob_device_enable_global_timestamp(self.inner, enabled, &mut err_ptr) };

OBError::consume(err_ptr)?;

Ok(())
}

/// Load the device preset
/// 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.
pub fn load_preset(&self, preset_name: &CStr) -> Result<(), OBError> {
Expand Down
36 changes: 36 additions & 0 deletions src/sys/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,42 @@ impl OBFrame {
self.inner
}

/// Get the frame timestamp (also known as device timestamp, hardware timestamp) of the frame in microseconds.
/// 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.
pub fn get_timestamp_us(&self) -> Result<u64, OBError> {
let mut err_ptr = std::ptr::null_mut();

let timestamp = unsafe { orb::ob_frame_get_timestamp_us(self.inner, &mut err_ptr) };

OBError::consume(err_ptr)?;

Ok(timestamp)
}

/// Get the system timestamp of the frame in microseconds.
/// The system timestamp is the time point when the frame was received by the host, on host clock domain.
pub fn get_system_timestamp_us(&self) -> Result<u64, OBError> {
let mut err_ptr = std::ptr::null_mut();

let timestamp = unsafe { orb::ob_frame_get_system_timestamp_us(self.inner, &mut err_ptr) };

OBError::consume(err_ptr)?;

Ok(timestamp)
}

/// Get the global timestamp of the frame in microseconds.
/// 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
pub fn get_global_timestamp_us(&self) -> Result<u64, OBError> {
let mut err_ptr = std::ptr::null_mut();

let timestamp = unsafe { orb::ob_frame_get_global_timestamp_us(self.inner, &mut err_ptr) };

OBError::consume(err_ptr)?;

Ok(timestamp)
}

/// Get the data buffer of a frame
pub fn get_data(&self) -> Result<&[u8], OBError> {
let mut err_ptr = std::ptr::null_mut();
Expand Down