Module async_api

Module async_api 

Source
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§

AsyncPickerFilterFuture
Future for async picker returning filter only
AsyncPickerFuture
Future for async picker with full result
AsyncSCContentSharingPicker
Async wrapper for SCContentSharingPicker (macOS 14.0+)
AsyncSCRecordingOutput
Async wrapper for SCRecordingOutput with event stream (macOS 15.0+)
AsyncSCScreenshotManager
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
AsyncScreenshotFuture
Future for async screenshot capture
AsyncShareableContentFuture
Future for async shareable content retrieval
NextRecordingEvent
Future for getting the next recording event
NextSample
Future for getting the next sample buffer

Enums§

RecordingEvent
Recording lifecycle event