1use crate::{
3 Format,
4 error::OrbbecError,
5 sys::stream::{OBCameraIntrinsic, OBStreamProfile, OBStreamProfileList},
6};
7
8pub trait StreamProfile: AsRef<OBStreamProfile> {}
10
11#[derive(Debug, Clone, Copy, PartialEq)]
13pub struct CameraIntrinsic {
14 pub fx: f32,
16 pub fy: f32,
18 pub cx: f32,
20 pub cy: f32,
22 pub width: u16,
24 pub height: u16,
26}
27
28impl From<OBCameraIntrinsic> for CameraIntrinsic {
29 fn from(intrinsic: OBCameraIntrinsic) -> Self {
30 CameraIntrinsic {
31 fx: intrinsic.fx(),
32 fy: intrinsic.fy(),
33 cx: intrinsic.cx(),
34 cy: intrinsic.cy(),
35 width: intrinsic.width() as u16,
36 height: intrinsic.height() as u16,
37 }
38 }
39}
40
41pub struct VideoStreamProfile {
43 inner: OBStreamProfile,
44}
45
46impl VideoStreamProfile {
47 pub(crate) fn new(inner: OBStreamProfile) -> Self {
48 VideoStreamProfile { inner }
49 }
50
51 pub(crate) fn inner(&self) -> &OBStreamProfile {
52 &self.inner
53 }
54
55 pub fn get_intrinsic(&self) -> Result<CameraIntrinsic, OrbbecError> {
57 self.inner
58 .get_video_intrinsic()
59 .map(|intrinsic| intrinsic.into())
60 .map_err(OrbbecError::from)
61 }
62}
63
64impl AsRef<OBStreamProfile> for VideoStreamProfile {
65 fn as_ref(&self) -> &OBStreamProfile {
66 &self.inner
67 }
68}
69impl StreamProfile for VideoStreamProfile {}
70
71pub struct StreamProfileList {
73 inner: OBStreamProfileList,
74}
75
76impl StreamProfileList {
77 pub(crate) fn new(inner: OBStreamProfileList) -> Self {
78 StreamProfileList { inner }
79 }
80
81 pub fn get_video_stream_profile(
88 &self,
89 width: u16,
90 height: u16,
91 format: Format,
92 fps: u8,
93 ) -> Result<VideoStreamProfile, OrbbecError> {
94 self.inner
95 .get_video_stream_profile(width as i32, height as i32, format, fps as i32)
96 .map(VideoStreamProfile::new)
97 .map_err(OrbbecError::from)
98 }
99}