use std::time::Duration;
use crate::{
SensorType,
device::Device,
frame::FrameSet,
stream::{StreamProfile, StreamProfileList},
sys::pipeline::{OBConfig, OBPipeline},
};
pub struct Config {
inner: OBConfig,
}
impl Config {
pub fn new() -> Result<Self, crate::error::OrbbecError> {
let config = OBConfig::new().map_err(crate::error::OrbbecError::from)?;
Ok(Config { inner: config })
}
pub fn enable_stream_with_profile<S: StreamProfile>(
&mut self,
profile: &S,
) -> Result<(), crate::error::OrbbecError> {
self.inner
.enable_stream_with_profile(profile.as_ref())
.map_err(crate::error::OrbbecError::from)
}
}
pub struct Pipeline {
inner: OBPipeline,
}
impl Pipeline {
pub fn new(device: &Device) -> Result<Self, crate::error::OrbbecError> {
let pipeline = OBPipeline::new(device.inner()).map_err(crate::error::OrbbecError::from)?;
Ok(Pipeline { inner: pipeline })
}
pub fn get_device(&mut self) -> Result<Device, crate::error::OrbbecError> {
let device = self
.inner
.get_device()
.map_err(crate::error::OrbbecError::from)?;
Ok(Device::new(device))
}
pub fn get_stream_profiles(
&mut self,
sensor: SensorType,
) -> Result<StreamProfileList, crate::error::OrbbecError> {
let profile_list = self
.inner
.get_stream_profile_list(sensor)
.map(StreamProfileList::new)
.map_err(crate::error::OrbbecError::from)?;
Ok(profile_list)
}
pub fn start(&mut self, config: &Config) -> Result<(), crate::error::OrbbecError> {
self.inner
.start_with_config(&config.inner)
.map_err(crate::error::OrbbecError::from)
}
pub fn set_frame_sync(&mut self, enable: bool) -> Result<(), crate::error::OrbbecError> {
let res = if enable {
self.inner.enable_frame_sync()
} else {
self.inner.disable_frame_sync()
};
res.map_err(crate::error::OrbbecError::from)
}
pub fn wait_for_frames(
&mut self,
timeout: Duration,
) -> Result<Option<FrameSet>, crate::error::OrbbecError> {
self.inner
.wait_for_frameset(timeout.as_millis() as u32)
.map(|frame| frame.map(FrameSet::from))
.map_err(crate::error::OrbbecError::from)
}
}