use super::*;
use std::ptr;
pub struct Camera<'a> {
pub(crate) device: &'a Device<'a>,
}
impl Camera<'_> {
pub(crate) fn new<'a>(
device: &'a Device<'a>,
configuration: &k4a_device_configuration_t,
) -> Result<Camera<'a>, Error> {
Error::from((device.factory.k4a_device_start_cameras)(
device.handle,
configuration,
))
.to_result(())?;
Ok(Camera::<'a> { device })
}
pub fn get_capture(&self, timeout_in_ms: i32) -> Result<Capture, Error> {
let mut handle: k4a_capture_t = ptr::null_mut();
Error::from((self.device.factory.k4a_device_get_capture)(
self.device.handle,
&mut handle,
timeout_in_ms,
))
.to_result_fn(&|| Capture::from_handle(self.device.factory, handle))
}
pub fn get_capture_wait_infinite(&self) -> Result<Capture, Error> {
self.get_capture(K4A_WAIT_INFINITE)
}
pub fn start_imu(&self) -> Result<Imu, Error> {
Imu::new(self.device)
}
}
impl Drop for Camera<'_> {
fn drop(&mut self) {
(self.device.factory.k4a_device_stop_cameras)(self.device.handle);
}
}