Skip to content

Commit

Permalink
spellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
liam committed Apr 19, 2024
1 parent 4ed0b07 commit 4919884
Show file tree
Hide file tree
Showing 21 changed files with 165 additions and 64 deletions.
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ name = "crabgrab"
version = "0.1.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["iosurface", "metal", "dxgi", "dx11", "bitmap", "screenshot", "wgpu"]
targets = ["x86_64-apple-darwin", "x86_64-pc-windows-msvc"]

[package.metadata.spellcheck]
config = "spellcheck/cfg.toml"

[features]
iosurface = []
metal = ["dep:metal"]
dxgi = []
dx11 = ["dxgi"]
bitmap = ["dep:bytemuck", "dep:half", "dx11"]
screenshot = ["bitmap"]
#content_picker = []
wgpu = ["dep:wgpu", "dep:winapi", "dx11", "dxgi", "metal"]

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Features:
- Screen and window capture supported
- Compatible with multiple GPU APIs:
- Wgpu
- DirectX 11
- DX11
- DXGI
- Metal
- IOSurface
- Easy frame bitmap generation
- Sound capture (wip)
- Sound capture (WIP)
- Platform specific extension features
- Screenshot facility

Expand Down
7 changes: 3 additions & 4 deletions examples/feature_wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crabgrab::prelude::*;
use crabgrab::feature::wgpu::WgpuCaptureConfigExt;
use crabgrab::feature::wgpu::WgpuVideoFrameExt;

#[allow(unused)]
struct Gfx {
device: wgpu::Device,
queue: wgpu::Queue,
Expand Down Expand Up @@ -56,7 +57,7 @@ fn main() {
.expect("Expected config with wgpu device");
let (tx_result, rx_result) = futures::channel::oneshot::channel();
let mut tx_result = Some(tx_result);
let stream = CaptureStream::new(token, config, move |event_result| {
let _stream = CaptureStream::new(token, config, move |event_result| {
match event_result {
Ok(event) => {
match event {
Expand Down Expand Up @@ -94,16 +95,14 @@ fn main() {
match frame_opt {
Some(frame) => {
println!("Got frame! getting wgpu texture...");
let wgpu_texture = frame.get_texture(crabgrab::feature::wgpu::WgpuVideoFramePlaneTexture::Rgba, Some("wgpu video frame"))
let wgpu_texture = frame.get_wgpu_texture(crabgrab::feature::wgpu::WgpuVideoFramePlaneTexture::Rgba, Some("wgpu video frame"))
.expect("Expected wgpu texture from video frame");
println!("Got wgpu texture! Size: {:?}", wgpu_texture.size());
//std::mem::forget(frame);
},
None => {
println!("Got None! Oh no!");
}
}
std::thread::sleep(Duration::from_millis(1000));
//std::mem::forget(stream);
});
}
4 changes: 4 additions & 0 deletions spellcheck/cfg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Hunspell]
search_dirs = ["."]
extra_dictionaries = ["crabgrab.dic"]
use_builtin = true
42 changes: 42 additions & 0 deletions spellcheck/crabgrab.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
41
chrominance
luminance
rgb
rgba
bgra
Bgra8888
cbcr
CbCr
y
YCbCr
ycbcr
capturable
Wgpu
IOSurface
IOSurfaces
F420
V420
VRAM
luma
chroma
backend
config
configs
u2
u8
u10
f16
crabgrab
CrabGrab
MacOS
DXGI
DX11
IOSurfaceRef
RgbaF16x4
Rgba1010102
WIP
APIs
🦀
🖥️
->
2D
9 changes: 5 additions & 4 deletions src/capturable_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{error::Error, fmt::{Debug, Display}};

use crate::{platform::platform_impl::{ImplCapturableApplication, ImplCapturableContent, ImplCapturableDisplay, ImplCapturableWindow}, util::Rect};

/// Represents an error that occured when enumerating capturable content
/// Represents an error that occurred when enumerating capturable content
#[derive(Debug, Clone)]
pub enum CapturableContentError {
Other(String)
Expand Down Expand Up @@ -32,7 +32,7 @@ impl Error for CapturableContentError {

/// Selects the kind of windows to enumerate for capture
pub struct CapturableWindowFilter {
/// Desktop windows are elements of the desktop environment, E.G. the dock on macos or the start bar on windows.
/// Desktop windows are elements of the desktop environment, E.G. the dock on MacOS or the start bar on Windows.
pub desktop_windows: bool,
/// Whether to restrict to onscreen windows
pub onscreen_only: bool,
Expand Down Expand Up @@ -99,6 +99,7 @@ impl CapturableContentFilter {
};
}

/// A collection of capturable content (windows, screens)
pub struct CapturableContent {
impl_capturable_content: ImplCapturableContent
}
Expand Down Expand Up @@ -242,15 +243,15 @@ impl CapturableDisplay {
unsafe impl Send for CapturableDisplay {}
unsafe impl Sync for CapturableDisplay {}

// Represents an application with capturable windows
/// Represents an application with capturable windows
pub struct CapturableApplication {
impl_capturable_application: ImplCapturableApplication
}

impl CapturableApplication {
/// Gets the "identifier" of the application
///
/// On Macos, this is the application bundle, and on windows, this is the application file name
/// On MacOS, this is the application bundle, and on windows, this is the application file name
pub fn identifier(&self) -> String {
self.impl_capturable_application.identifier()
}
Expand Down
20 changes: 9 additions & 11 deletions src/capture_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum StreamEvent {
End,
}

/// This represents an error during a stream, for example a failure to retreive a video or audio frame
/// This represents an error during a stream, for example a failure to retrieve a video or audio frame
#[derive(Debug, Clone)]
pub enum StreamError {
Other(String),
Expand Down Expand Up @@ -128,7 +128,7 @@ pub struct AudioCaptureConfig {

impl AudioCaptureConfig {
/// Creates a new audio capture config with default settings:
/// * 24000 hz
/// * 24000 Hz
/// * Mono
pub fn new() -> Self {
Self {
Expand All @@ -143,17 +143,17 @@ impl AudioCaptureConfig {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum CapturePixelFormat {
/// One plane, 4 channels, 8 bits per channel: {b: u8, g: u8, r: u8, a: u8}, full range: [0, 255]
/// One plane, 4 channels, 8 bits per channel: { b: u8, g: u8, r: u8, a: u8 }, full range: [0, 255]
Bgra8888,
/// One plane, 4 channels, 10 bits per color channel, two bits for alpha: {a: u2, r: u10, g: u10, b: u10}, rgb range: [0, 1023], alpha range: [0, 3]
/// One plane, 4 channels, 10 bits per color channel, two bits for alpha: { a: u2, r: u10, g: u10, b: u10 }, rgb range: [0, 1023], alpha range: [0, 3]
Argb2101010,
/// Two planes:
/// * 1 channel, luminance, 8 bits per pixel, video range: [16, 240]
/// * 2 channels, chroma (cb, cr) 8 bits bits per channel per two pixels vertically, range: [0, 255]
/// * 1 channel, luminance (Y), 8 bits per pixel, video range: [16, 240]
/// * 2 channels, chrominance (CbCr) 8 bits bits per channel per two pixels vertically, range: [0, 255]
V420,
/// Two planes:
/// * 1 channel, luminance, 8 bits per pixel, full range: [0, 255]
/// * 2 channels, chroma (cb, cr) 8 bits bits per channel per two pixels vertically, range: [0, 255]
/// * 1 channel, luminance (Y), 8 bits per pixel, full range: [0, 255]
/// * 2 channels, chrominance (CbCr) 8 bits bits per channel per two pixels vertically, range: [0, 255]
F420,
}

Expand Down Expand Up @@ -283,7 +283,7 @@ pub struct CaptureStream {

unsafe impl Send for CaptureStream {}

/// Represents programatic capture access
/// Represents programmatic capture access
#[derive(Clone, Copy, Debug)]
pub struct CaptureAccessToken {
pub(crate) impl_capture_access_token: ImplCaptureAccessToken
Expand Down Expand Up @@ -318,8 +318,6 @@ impl CaptureStream {
}

/// Gets the implementation's supported pixel formats
///
/// Note that the returned formats may not work for all capture modalities (eg, window vs display)
pub fn supported_pixel_formats() -> &'static [CapturePixelFormat] {
ImplCaptureStream::supported_pixel_formats()
}
Expand Down
4 changes: 2 additions & 2 deletions src/feature/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ pub enum VideoRange {

/// A YCbCr image, corresponding to either V420 or F420 pixel formats.
///
/// Dual-planar, with luma (Y) in one plane, and chroma (CbCr) in another.
/// Dual-planar, with luminance (Y) in one plane, and chrominance (CbCr) in another.
/// Note that each plane may have a different size, as with V420 format, where
/// the chroma plane is 2x2 blocks, but luma is per-pixel
/// the chroma plane is 2 by 2 blocks, but luma is per-pixel
pub struct FrameBitmapYCbCr {
pub luma_data: Box<[u8]>,
pub luma_width: usize,
Expand Down
6 changes: 3 additions & 3 deletions src/feature/dx11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Error for WindowsDx11VideoFrameError {
}
}

/// A video frame which can yield a d3d11 surface
/// A video frame which can yield a DX11 surface
pub trait WindowsDx11VideoFrame {
/// Get the DX11 surface representing the video frame's texture memory, as well as the pixel format
fn get_dx11_surface(&self) -> Result<(IDirect3DSurface, DirectXPixelFormat), WindowsDx11VideoFrameError>;
Expand All @@ -60,9 +60,9 @@ impl WindowsDx11VideoFrame for VideoFrame {
}
}

/// A capture stream which can interoperate with D3D11
/// A capture stream which can inter-operate with DX11
pub trait WindowsDx11CaptureStream {
/// Get the underlying D3D11 device used for frame capture
/// Get the underlying DX11 device used for frame capture
fn get_dx11_device(&self) -> ID3D11Device;
}

Expand Down
8 changes: 4 additions & 4 deletions src/feature/dxgi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Error for WindowsDxgiVideoFrameError {
}
}

/// A video frame which can interoperate with DXGI
/// A video frame which can inter-operate with DXGI
pub trait WindowsDxgiVideoFrame {
/// Get the surface texture for this video frame
fn get_dxgi_surface(&self) -> Result<(windows::Win32::Graphics::Dxgi::IDXGISurface, DirectXPixelFormat), WindowsDxgiVideoFrameError>;
Expand Down Expand Up @@ -85,11 +85,11 @@ impl Error for WindowsDxgiCaptureStreamError {
}
}

/// A capture stream which can interoperate with DXGI
/// A capture stream which can inter-operate with DXGI
pub trait WindowsDxgiCaptureStream {
/// Get the dxgi adapter used by the capture stream for frame generation
/// Get the DXGI adapter used by the capture stream for frame generation
fn get_dxgi_adapter(&self) -> Result<windows::Win32::Graphics::Dxgi::IDXGIAdapter, WindowsDxgiCaptureStreamError>;
/// Get the dxgi device used by the capture stream for frame generation
/// Get the DXGI device used by the capture stream for frame generation
fn get_dxgi_device(&self) -> windows::Win32::Graphics::Dxgi::IDXGIDevice;
}

Expand Down
6 changes: 3 additions & 3 deletions src/feature/iosurface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::Display;

use crate::{platform::{macos::{frame::MacosVideoFrame, objc_wrap::IOSurfaceRef}, platform_impl::objc_wrap::{IOSurfaceDecrementUseCount, IOSurfaceIncrementUseCount}}, prelude::VideoFrame};

/// A Macos IOSurface instance
/// A MacOS IOSurface instance
pub struct IoSurface(IOSurfaceRef);

impl IoSurface {
Expand Down Expand Up @@ -36,9 +36,9 @@ impl Drop for IoSurface {
}
}

/// A video frame which can interoperate using IOSurfaces
/// A video frame which can inter-operate with any MacOS GPU API using IOSurfaces
pub trait MacosIoSurfaceVideoFrameExt {
/// Get the iosurface representing the video frame's texture
/// Get the IOSurface representing the video frame's texture
fn get_iosurface(&self) -> Result<IoSurface, GetIoSurfaceError>;
}

Expand Down
10 changes: 5 additions & 5 deletions src/feature/metal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::platform::macos::frame::MacosVideoFrame;
pub enum MetalVideoFramePlaneTexture {
/// The single RGBA plane for an RGBA format frame
Rgba,
/// The Luminance (brightness) plane for a YCbCr format frame
/// The Luminance (Y, Brightness) plane for a YCbCr format frame
Luminance,
/// The Chroma (red/blue) plane for a YCbCr format frame
/// The Chrominance (CbCr, Blue/Red) plane for a YCbCr format frame
Chroma
}

Expand Down Expand Up @@ -67,12 +67,12 @@ impl Error for MacosVideoFrameError {
/// A video frame which can be used to create metal textures
pub trait MetalVideoFrameExt {
/// Get the texture for the given plane of the video frame
fn get_texture(&self, plane: MetalVideoFramePlaneTexture) -> Result<metal::Texture, MacosVideoFrameError>;
fn get_metal_texture(&self, plane: MetalVideoFramePlaneTexture) -> Result<metal::Texture, MacosVideoFrameError>;
}

#[cfg(feature="metal")]
impl MetalVideoFrameExt for VideoFrame {
fn get_texture(&self, plane: MetalVideoFramePlaneTexture) -> Result<metal::Texture, MacosVideoFrameError> {
fn get_metal_texture(&self, plane: MetalVideoFramePlaneTexture) -> Result<metal::Texture, MacosVideoFrameError> {
let iosurface_and_metal_device = match &self.impl_video_frame {
MacosVideoFrame::SCStream(frame) => {
match frame.sample_buffer.get_image_buffer() {
Expand Down Expand Up @@ -149,7 +149,7 @@ impl MetalVideoFrameExt for VideoFrame {
}
}

/// A capture stream which interoperates with Metal
/// A capture stream which inter-operates with Metal
pub trait MetalCaptureStreamExt {
/// Get the metal device used for frame capture
fn get_metal_device(&self) -> metal::Device;
Expand Down
14 changes: 14 additions & 0 deletions src/feature/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
#[cfg(feature = "metal")]
#[cfg(target_os="macos")]
/// Frame -> Metal Texture conversion
/// (requires `metal` feature)
pub mod metal;
#[cfg(feature = "dxgi")]
#[cfg(target_os="windows")]
/// Frame -> DXGI Surface conversion
/// (requires `dxgi` feature)
pub mod dxgi;
#[cfg(feature = "dx11")]
#[cfg(target_os="windows")]
/// Frame -> DX11 Surface/Texture conversion
/// (requires `dx11` feature)
pub mod dx11;
#[cfg(feature = "iosurface")]
#[cfg(target_os="macos")]
/// Frame -> IOSurface conversion
/// (requires `iosurface` feature)
pub mod iosurface;
#[cfg(feature = "bitmap")]
/// Frame to Bitmap conversion
/// (requires `bitmap` feature)
pub mod bitmap;
#[cfg(feature = "wgpu")]
/// Frame -> Wgpu Texture conversion
/// (requires `wgpu` feature)
pub mod wgpu;
#[cfg(feature = "screenshot")]
/// Screenshot utility function
/// (requires `screenshot` feature)
pub mod screenshot;
//#[cfg(feature = "content_picker")]
//pub mod content_picker;
Loading

0 comments on commit 4919884

Please sign in to comment.