Skip to content

Commit 253b75e

Browse files
committed
replace tuple return with a proper struct
1 parent 22b06d5 commit 253b75e

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zbl/examples/trivial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::Instant;
22

33
use clap::Parser;
44
use opencv::{highgui, prelude::*};
5-
use zbl::{init, Capture, Window};
5+
use zbl::{init, Capture, Frame, Window};
66

77
#[derive(Parser, Debug)]
88
#[clap(version)]
@@ -28,7 +28,7 @@ fn main() {
2828
let mut tt = 0f32;
2929
loop {
3030
let t = Instant::now();
31-
if let Some((texture, ptr)) = capturer.grab().expect("failed to get frame") {
31+
if let Some(Frame { texture, ptr }) = capturer.grab().expect("failed to get frame") {
3232
let mat = unsafe {
3333
Mat::new_size_with_data(
3434
opencv::core::Size::new(texture.desc.Width as i32, texture.desc.Height as i32),

zbl/src/capture.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ extern "system" fn object_destroyed_cb(
7171
}
7272
}
7373

74+
pub struct Frame<'a> {
75+
pub texture: &'a StagingTexture,
76+
pub ptr: D3D11_MAPPED_SUBRESOURCE,
77+
}
78+
7479
pub struct Capture {
7580
device: ID3D11Device,
7681
direct3d_device: IDirect3DDevice,
@@ -82,8 +87,6 @@ pub struct Capture {
8287
frame_source: Receiver<Option<Direct3D11CaptureFrame>>,
8388
session: GraphicsCaptureSession,
8489
staging_texture: Option<StagingTexture>,
85-
#[allow(unused)]
86-
staging_texture_ptr: Option<D3D11_MAPPED_SUBRESOURCE>,
8790
content_size: SizeInt32,
8891
stopped: bool,
8992
}
@@ -170,7 +173,6 @@ impl Capture {
170173
frame_source: receiver,
171174
session,
172175
staging_texture: None,
173-
staging_texture_ptr: None,
174176
content_size: Default::default(),
175177
stopped: false,
176178
})
@@ -195,15 +197,18 @@ impl Capture {
195197
/// * `Ok(Some(...))` if there is a frame and it's been successfully captured;
196198
/// * `Ok(None)` if no frames can be received from the application (i.e. when the window was closed).
197199
/// * `Err(...)` if an error has occured while capturing a frame.
198-
pub fn grab(&mut self) -> Result<Option<(&StagingTexture, D3D11_MAPPED_SUBRESOURCE)>> {
200+
pub fn grab(&mut self) -> Result<Option<Frame>> {
199201
if self.grab_next()? {
200202
let texture = self.staging_texture.as_ref().unwrap();
201203
let ptr = self
202204
.staging_texture
203205
.as_ref()
204206
.unwrap()
205207
.as_mapped(&self.context)?;
206-
Ok(Some((texture, ptr.clone())))
208+
Ok(Some(Frame {
209+
texture,
210+
ptr: ptr.clone(),
211+
}))
207212
} else {
208213
Ok(None)
209214
}

zbl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pub mod staging_texture;
33
pub mod util;
44
pub mod window;
55

6-
pub use capture::Capture;
6+
pub use capture::{Capture, Frame};
77
pub use window::Window;
88

99
// re-export winapi

zbl_py/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zbl_py"
3-
version = "0.0.1"
3+
version = "0.0.3"
44
edition = "2021"
55

66
[lib]

zbl_py/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Capture {
7777
}
7878

7979
fn _grab(&mut self) -> Result<Option<Frame>> {
80-
if let Some((texture, ptr)) = self.inner.grab()? {
80+
if let Some(::zbl::Frame { texture, ptr }) = self.inner.grab()? {
8181
Ok(Some(Frame {
8282
width: texture.desc.Width,
8383
height: texture.desc.Height,

0 commit comments

Comments
 (0)