1use std::time::Duration;
3
4use crate::{
5 SensorType,
6 device::Device,
7 frame::FrameSet,
8 stream::{StreamProfile, StreamProfileList},
9 sys::pipeline::{OBConfig, OBPipeline},
10};
11
12pub struct Config {
14 inner: OBConfig,
15}
16
17impl Config {
18 pub fn new() -> Result<Self, crate::error::OrbbecError> {
20 let config = OBConfig::new().map_err(crate::error::OrbbecError::from)?;
21
22 Ok(Config { inner: config })
23 }
24
25 pub fn enable_stream_with_profile<S: StreamProfile>(
29 &mut self,
30 profile: &S,
31 ) -> Result<(), crate::error::OrbbecError> {
32 self.inner
33 .enable_stream_with_profile(profile.as_ref())
34 .map_err(crate::error::OrbbecError::from)
35 }
36}
37
38pub struct Pipeline {
40 inner: OBPipeline,
41}
42
43impl Pipeline {
44 pub fn new(device: &Device) -> Result<Self, crate::error::OrbbecError> {
48 let pipeline = OBPipeline::new(device.inner()).map_err(crate::error::OrbbecError::from)?;
49
50 Ok(Pipeline { inner: pipeline })
51 }
52
53 pub fn get_device(&mut self) -> Result<Device, crate::error::OrbbecError> {
55 let device = self
56 .inner
57 .get_device()
58 .map_err(crate::error::OrbbecError::from)?;
59
60 Ok(Device::new(device))
61 }
62
63 pub fn get_stream_profiles(
67 &mut self,
68 sensor: SensorType,
69 ) -> Result<StreamProfileList, crate::error::OrbbecError> {
70 let profile_list = self
71 .inner
72 .get_stream_profile_list(sensor)
73 .map(StreamProfileList::new)
74 .map_err(crate::error::OrbbecError::from)?;
75
76 Ok(profile_list)
77 }
78
79 pub fn start(&mut self, config: &Config) -> Result<(), crate::error::OrbbecError> {
83 self.inner
84 .start_with_config(&config.inner)
85 .map_err(crate::error::OrbbecError::from)
86 }
87
88 pub fn set_frame_sync(&mut self, enable: bool) -> Result<(), crate::error::OrbbecError> {
92 let res = if enable {
93 self.inner.enable_frame_sync()
94 } else {
95 self.inner.disable_frame_sync()
96 };
97
98 res.map_err(crate::error::OrbbecError::from)
99 }
100
101 pub fn wait_for_frames(
105 &mut self,
106 timeout: Duration,
107 ) -> Result<Option<FrameSet>, crate::error::OrbbecError> {
108 self.inner
109 .wait_for_frameset(timeout.as_millis() as u32)
110 .map(|frame| frame.map(FrameSet::from))
111 .map_err(crate::error::OrbbecError::from)
112 }
113}