use crate::{
Format,
error::OrbbecError,
sys::stream::{OBCameraIntrinsic, OBStreamProfile, OBStreamProfileList},
};
pub trait StreamProfile: AsRef<OBStreamProfile> {}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CameraIntrinsic {
pub fx: f32,
pub fy: f32,
pub cx: f32,
pub cy: f32,
pub width: u16,
pub height: u16,
}
impl From<OBCameraIntrinsic> for CameraIntrinsic {
fn from(intrinsic: OBCameraIntrinsic) -> Self {
CameraIntrinsic {
fx: intrinsic.fx(),
fy: intrinsic.fy(),
cx: intrinsic.cx(),
cy: intrinsic.cy(),
width: intrinsic.width() as u16,
height: intrinsic.height() as u16,
}
}
}
pub struct VideoStreamProfile {
inner: OBStreamProfile,
}
impl VideoStreamProfile {
pub(crate) fn new(inner: OBStreamProfile) -> Self {
VideoStreamProfile { inner }
}
pub(crate) fn inner(&self) -> &OBStreamProfile {
&self.inner
}
pub fn get_intrinsic(&self) -> Result<CameraIntrinsic, OrbbecError> {
self.inner
.get_video_intrinsic()
.map(|intrinsic| intrinsic.into())
.map_err(OrbbecError::from)
}
}
impl AsRef<OBStreamProfile> for VideoStreamProfile {
fn as_ref(&self) -> &OBStreamProfile {
&self.inner
}
}
impl StreamProfile for VideoStreamProfile {}
pub struct StreamProfileList {
inner: OBStreamProfileList,
}
impl StreamProfileList {
pub(crate) fn new(inner: OBStreamProfileList) -> Self {
StreamProfileList { inner }
}
pub fn get_video_stream_profile(
&self,
width: u16,
height: u16,
format: Format,
fps: u8,
) -> Result<VideoStreamProfile, OrbbecError> {
self.inner
.get_video_stream_profile(width as i32, height as i32, format, fps as i32)
.map(VideoStreamProfile::new)
.map_err(OrbbecError::from)
}
}