Skip to main content

Module async_api

Module async_api 

Source
Available on crate feature async only.
Expand description

Async API for ScreenCaptureKit

This module provides async versions of operations when the async feature is enabled. The async API is executor-agnostic and works with any async runtime (Tokio, async-std, smol, etc.).

§Available Types

TypeDescription
AsyncSCShareableContentAsync content queries
AsyncSCStreamAsync stream with frame iteration
AsyncSCScreenshotManagerAsync screenshot capture (macOS 14.0+)
AsyncSCContentSharingPickerAsync content picker UI (macOS 14.0+)
AsyncSCRecordingOutputAsync recording with events (macOS 15.0+)

§Runtime Agnostic Design

This async API uses only std types and works with any async runtime:

  • Uses callback-based Swift FFI for true async operations
  • Uses std::sync::{Arc, Mutex} for synchronization
  • Uses std::task::{Poll, Waker} for async primitives
  • Uses std::future::Future trait

§Examples

§Basic Async Content Query

use screencapturekit::async_api::AsyncSCShareableContent;

let content = AsyncSCShareableContent::get().await?;
println!("Found {} displays", content.displays().len());
println!("Found {} windows", content.windows().len());

§Async Stream with Frame Iteration

use screencapturekit::async_api::{AsyncSCShareableContent, AsyncSCStream};
use screencapturekit::stream::configuration::SCStreamConfiguration;
use screencapturekit::stream::content_filter::SCContentFilter;
use screencapturekit::stream::output_type::SCStreamOutputType;

let content = AsyncSCShareableContent::get().await?;
let display = &content.displays()[0];
let filter = SCContentFilter::create().with_display(display).with_excluding_windows(&[]).build();
let config = SCStreamConfiguration::new().with_width(1920).with_height(1080);

let stream = AsyncSCStream::new(&filter, &config, 30, SCStreamOutputType::Screen);
stream.start_capture()?;

// Process frames asynchronously
for _ in 0..100 {
    if let Some(frame) = stream.next().await {
        println!("Got frame at {:?}", frame.presentation_timestamp());
    }
}

stream.stop_capture()?;

Structs§

AsyncPickerFilterFuturemacos_14_0
Future for async picker returning filter only
AsyncPickerFuturemacos_14_0
Future for async picker with full result
AsyncSCContentSharingPickermacos_14_0
Async wrapper for SCContentSharingPicker (macOS 14.0+)
AsyncSCRecordingOutputmacos_15_0
Async wrapper for SCRecordingOutput with event stream (macOS 15.0+)
AsyncSCScreenshotManagermacos_14_0
Async wrapper for SCScreenshotManager
AsyncSCShareableContent
Async wrapper for SCShareableContent
AsyncSCShareableContentOptions
Options for async shareable content retrieval
AsyncSCStream
Async wrapper for SCStream with integrated frame iteration
AsyncScreenshotFuturemacos_14_0
Future for async screenshot capture
AsyncShareableContentFuture
Future for async shareable content retrieval
NextRecordingEventmacos_15_0
Future for getting the next recording event
NextSample
Future for getting the next sample buffer

Enums§

RecordingEventmacos_15_0
Recording lifecycle event