Skip to content

Commit 9a06b4f

Browse files
committed
Allow querying video parameters on streams
Allows fetching width/height/fps/format on video streams. Topic: video-metadata
1 parent d28b0aa commit 9a06b4f

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

src/stream.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,35 @@ impl VideoStreamProfile {
5959
.map(|intrinsic| intrinsic.into())
6060
.map_err(OrbbecError::from)
6161
}
62+
63+
/// Get the width of this video stream profile in pixels
64+
pub fn width(&self) -> u32 {
65+
self.inner
66+
.get_video_width()
67+
.map_err(OrbbecError::from)
68+
.unwrap()
69+
}
70+
71+
/// Get the height of this video stream profile in pixels
72+
pub fn height(&self) -> u32 {
73+
self.inner
74+
.get_video_height()
75+
.map_err(OrbbecError::from)
76+
.unwrap()
77+
}
78+
79+
/// Get the frame rate of this video stream profile
80+
pub fn fps(&self) -> u32 {
81+
self.inner
82+
.get_video_fps()
83+
.map_err(OrbbecError::from)
84+
.unwrap()
85+
}
86+
87+
/// Get the pixel format of this stream profile
88+
pub fn format(&self) -> Result<Format, OrbbecError> {
89+
self.inner.get_format().map_err(OrbbecError::from)
90+
}
6291
}
6392

6493
impl AsRef<OBStreamProfile> for VideoStreamProfile {

src/sys/stream.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,53 @@ impl OBStreamProfile {
7272

7373
Ok(OBCameraIntrinsic::from(intrinsics))
7474
}
75+
76+
/// Get stream profile format
77+
pub fn get_format(&self) -> Result<OBFormat, OBError> {
78+
let mut err_ptr = std::ptr::null_mut();
79+
80+
let format = unsafe { orb::ob_stream_profile_get_format(self.inner, &mut err_ptr) };
81+
82+
OBError::consume(err_ptr)?;
83+
84+
Ok(format.into())
85+
}
86+
87+
/// Get the frame rate of the video stream.
88+
/// Returns error if the profile is not a video stream profile.
89+
pub fn get_video_fps(&self) -> Result<u32, OBError> {
90+
let mut err_ptr = std::ptr::null_mut();
91+
92+
let fps = unsafe { orb::ob_video_stream_profile_get_fps(self.inner, &mut err_ptr) };
93+
94+
OBError::consume(err_ptr)?;
95+
96+
Ok(fps)
97+
}
98+
99+
/// Get the width of the video stream.
100+
/// Returns error if the profile is not a video stream profile.
101+
pub fn get_video_width(&self) -> Result<u32, OBError> {
102+
let mut err_ptr = std::ptr::null_mut();
103+
104+
let width = unsafe { orb::ob_video_stream_profile_get_width(self.inner, &mut err_ptr) };
105+
106+
OBError::consume(err_ptr)?;
107+
108+
Ok(width)
109+
}
110+
111+
/// Get the height of the video stream.
112+
/// Returns error if the profile is not a video stream profile.
113+
pub fn get_video_height(&self) -> Result<u32, OBError> {
114+
let mut err_ptr = std::ptr::null_mut();
115+
116+
let height = unsafe { orb::ob_video_stream_profile_get_height(self.inner, &mut err_ptr) };
117+
118+
OBError::consume(err_ptr)?;
119+
120+
Ok(height)
121+
}
75122
}
76123

77124
/// List of video stream profiles

0 commit comments

Comments
 (0)