### Setup and Run Tauri App Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Instructions to set up and run the Tauri application example. This involves navigating to the example directory, installing npm dependencies, and starting the development server. ```bash cd examples/22_tauri_app && npm install && npm run tauri dev ``` -------------------------------- ### Run Basic Screen Capture Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/README.md Execute the basic screen capture example using Cargo. This is a good starting point for understanding the library's core functionality. ```bash cargo run --example 01_basic_capture ``` -------------------------------- ### Run wgpu Integration Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example that integrates with wgpu for graphics rendering. This example does not require any special features. ```bash cargo run --example 18_wgpu_integration ``` -------------------------------- ### Run FFmpeg Encoding Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example for FFmpeg encoding. This requires FFmpeg to be installed via a package manager like Homebrew. ```bash cargo run --example 19_ffmpeg_encoding ``` -------------------------------- ### Run Bevy Streaming Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example for streaming with the Bevy game engine. This example does not require any special features. ```bash cargo run --example 21_bevy_streaming ``` -------------------------------- ### Run Basic Screencapturekit-rs Examples Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute fundamental screencapturekit-rs examples that do not require any special features. These examples cover basic capture, window capture, stream updates, and application capture. ```bash cargo run --example 01_basic_capture cargo run --example 02_window_capture cargo run --example 12_stream_updates cargo run --example 14_app_capture ``` -------------------------------- ### Run Metal Textures Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example demonstrating the use of Metal textures. This example does not require any special features. ```bash cargo run --example 17_metal_textures ``` -------------------------------- ### Run Screencapturekit-rs Example with All Features Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the asynchronous screencapturekit-rs example with all available features enabled using the '--all-features' flag. ```bash cargo run --example 08_async --all-features ``` -------------------------------- ### Run egui Viewer Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example that uses egui for a viewer interface. This example does not require any special features. ```bash cargo run --example 20_egui_viewer ``` -------------------------------- ### Basic Screen Capture Workflow Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/OVERVIEW.md This snippet demonstrates the 5-step process for a basic screen capture. It involves getting shareable content, creating a content filter, configuring stream settings, initializing the stream, and starting the capture. ```rust let content = SCShareableContent::get()?; let display = &content.displays()[0]; let filter = SCContentFilter::create().with_display(display).build(); let config = SCStreamConfiguration::new().with_width(1920).with_height(1080); let mut stream = SCStream::new(&filter, &config); stream.add_output_handler(handler, SCStreamOutputType::Screen); stream.start_capture()?; ``` -------------------------------- ### Complete Screen Recording Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/RecordingOutput.md This snippet demonstrates how to record the screen for a specified duration, save it to a file, and monitor its progress. It includes setup for content filtering, stream configuration, and output settings like codec and file type. Ensure the 'macos_15_0' feature is enabled. ```rust #[cfg(feature = "macos_15_0")] fn record_screen() -> Result<(), Box> { use screencapturekit::prelude::*; use screencapturekit::recording_output::{ SCRecordingOutput, SCRecordingOutputConfiguration, SCRecordingOutputCodec, SCRecordingOutputFileType }; use std::path::PathBuf; use std::time::Duration; // Get content let content = SCShareableContent::get()?; let display = &content.displays()[0]; // Create filter and config let filter = SCContentFilter::create() .with_display(display) .with_excluding_windows(&[]) .build(); let stream_config = SCStreamConfiguration::new() .with_width(1920) .with_height(1080) .with_pixel_format(PixelFormat::BGRA); // Create recording output let output_path = PathBuf::from("/tmp/screen_recording.mp4"); let recording_config = SCRecordingOutputConfiguration::new() .with_output_url(&output_path) .with_video_codec(SCRecordingOutputCodec::H264) .with_output_file_type(SCRecordingOutputFileType::MP4); let mut recording = SCRecordingOutput::new(&recording_config) .ok_or("Failed to create recording output")?; // Set optional delegate for feedback struct Delegate; impl screencapturekit::recording_output::SCRecordingOutputDelegate for Delegate { fn recording_output_did_finish_successfully(&self) { println!("Recording finished!"); } fn recording_output_did_fail_with_error(&self, error: SCError) { eprintln!("Recording error: {}", error); } fn recording_output_did_pause(&self) {} } recording.set_delegate(Box::new(Delegate)); // Create stream and start recording let mut stream = SCStream::new(&filter, &stream_config); stream.add_recording_output(&recording)?; stream.start_capture()?; // Record for 10 seconds, periodically checking stats for _ in 0..10 { std::thread::sleep(Duration::from_secs(1)); let duration = recording.recorded_duration(); let size = recording.recorded_file_size(); println!( "Recording: {:.1}s, {} bytes", duration.to_seconds(), size ); } // Stop recording stream.remove_recording_output(&recording)?; stream.stop_capture()?; println!("Recording saved to: {:?}", output_path); println!("Final size: {} bytes", recording.recorded_file_size()); Ok(()) } ``` -------------------------------- ### Run Async Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the asynchronous screencapturekit-rs example. This requires the 'async' feature to be enabled. ```bash cargo run --example 08_async --features async ``` -------------------------------- ### Run Recording Output Example with Feature Flag Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/README.md Execute the example for direct-to-file recording, which requires the 'macos_15_0' feature flag. This demonstrates recording screen content directly to a file. ```bash cargo run --example 10_recording_output --features macos_15_0 ``` -------------------------------- ### Run Metal GUI Screencapturekit-rs Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs example that integrates with Metal for GUI rendering, requiring the 'macos_14_0' feature. ```bash cargo run --example 16_full_metal_app --features macos_14_0 ``` -------------------------------- ### Start Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Begins the screen capture process for an initialized asynchronous stream. This operation returns immediately on success or an error if setup fails. ```rust pub fn start_capture(&self) -> Result<(), SCError> ``` ```rust stream.start_capture()?; ``` -------------------------------- ### Run Full Metal App Example with Recording (macOS 15.0+) Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Build and run the full metal app example with video recording support. Requires macOS 15.0 or later. ```bash cargo run --example 16_full_metal_app --features macos_15_0 ``` -------------------------------- ### Run Client/Server Screen Sharing Examples Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the client and server components for screen sharing using screencapturekit-rs. These examples are intended to be run in separate terminals. ```bash cargo run --example 23_client_server_server # Terminal 1 cargo run --example 23_client_server_client # Terminal 2 ``` -------------------------------- ### Capture and Save a Simple Screenshot Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/ScreenshotManager.md Captures a single screenshot of a display and prepares its pixel data. This example shows the basic setup for capturing an image and includes a commented-out section for saving it to a PNG file using the `image` crate. ```rust #[cfg(feature = "macos_14_0")] use screencapturekit::screenshot_manager::SCScreenshotManager; let content = SCShareableContent::get()?; 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 image = SCScreenshotManager::capture_image(&filter, &config)?; let pixels = image.bgra_data()?; // Save to PNG (example using `image` crate) // let img = image::RgbaImage::from_raw(w, h, rgba_pixels).unwrap(); // img.save("screenshot.png")?; ``` -------------------------------- ### Run macOS 15+ Screencapturekit-rs Examples Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute screencapturekit-rs examples that require features introduced in macOS 15.0. This includes recording output and advanced configuration options. ```bash cargo run --example 10_recording_output --features macos_15_0 cargo run --example 13_advanced_config --features macos_15_0 ``` -------------------------------- ### Run Async Example with Feature Flags Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/README.md Execute the async API example, which requires 'async' and 'macos_14_0' feature flags. This showcases async patterns and runtime-agnostic usage. ```bash cargo run --example 08_async --features "async,macos_14_0" ``` -------------------------------- ### Install and Run Tauri App Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/22_tauri_app/README.md Install Node dependencies and run the Tauri application in development or build it for production. ```bash cd examples/22_tauri_app # Install Node dependencies npm install # Run in development mode npm run tauri dev # Build for production npm run tauri build ``` -------------------------------- ### Run macOS 26+ HDR Screenshot Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the screencapturekit-rs screenshot example with support for HDR screenshots, requiring features available on macOS 26.0 and later. ```bash cargo run --example 05_screenshot --features macos_26_0 ``` -------------------------------- ### Run Full Metal App Example with HDR Screenshots (macOS 26.0+) Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Build and run the full metal app example with HDR screenshot support. Requires macOS 26.0 or later. ```bash cargo run --example 16_full_metal_app --features macos_26_0 ``` -------------------------------- ### Get Default Content Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves all available displays, windows, and running applications for screen capture. This is the primary method to start a capture workflow. ```APIDOC ## Get Default Content ### Description Retrieves all available displays, windows, and running applications for screen capture. This is the primary method to start a capture workflow. ### Method `pub fn get() -> Result` ### Parameters None ### Returns `Result` - An object containing all available content. ### Errors - `PermissionError`: Screen recording permission not granted. - `StreamError(msg)`: System error during content enumeration. ### Example ```rust use screencapturekit::prelude::* fn main() -> Result<(), Box> { let content = SCShareableContent::get()?; println!("Displays: {}", content.displays().len()); println!("Windows: {}", content.windows().len()); Ok(()) } ``` ``` -------------------------------- ### Run macOS 14+ Screencapturekit-rs Examples Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute screencapturekit-rs examples that utilize features available on macOS 14.0 and later. This includes screenshotting and content picker functionalities. ```bash cargo run --example 05_screenshot --features macos_14_0 cargo run --example 11_content_picker --features macos_14_0 ``` -------------------------------- ### Registering Handlers Before Starting Stream Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/errors.md Demonstrates the correct order for registering output handlers and starting a stream to avoid `NotificationsDisabledWhileNotRunning` errors. ```rust let mut stream = SCStream::new(&filter, &config); // Register handlers BEFORE starting stream.add_output_handler(handler, SCStreamOutputType::Screen); // Now start stream.start_capture()?; ``` -------------------------------- ### Run Async Screencapturekit-rs Example with macOS 14+ Picker Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/examples/README.md Execute the asynchronous screencapturekit-rs example with support for the macOS 14.0 content picker. This requires both 'async' and 'macos_14_0' features. ```bash cargo run --example 08_async --features "async,macos_14_0" ``` -------------------------------- ### Start Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Starts the screen capture process for an initialized `AsyncSCStream`. This method must be called before attempting to retrieve frames. ```APIDOC ## Start Capture ### Description Starts the screen capture process for an initialized `AsyncSCStream`. This method must be called before attempting to retrieve frames. ### Method Signature `pub fn start_capture(&self) -> Result<(), SCError>` ### Returns `Ok(())` on success, `Err(SCError)` if setup fails. ### Example ```rust stream.start_capture()?; ``` ``` -------------------------------- ### Install and select Xcode Command Line Tools Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/docs/MIGRATION.md Ensure Xcode Command Line Tools are installed and selected for the build script to function correctly. This step is crucial for SDK detection and build integrity. ```bash xcode-select --install sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer ``` -------------------------------- ### Async Main Function with Tokio Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Example of initializing an async content getter using Tokio's runtime. ```rust #[tokio::main] async fn main() { let content = AsyncSCShareableContent::get().await.unwrap(); } ``` -------------------------------- ### Async Main Function with smol Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Example of initializing an async content getter using smol's runtime. ```rust fn main() { smol::block_on(async { let content = AsyncSCShareableContent::get().await.unwrap(); }) } ``` -------------------------------- ### Start Screen Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStream.md Initiates the screen capture process. Ensure the stream is properly configured before calling. Capture permissions must be granted. ```rust stream.start_capture()?; std::thread::sleep(Duration::from_secs(5)); stream.stop_capture()?; ``` -------------------------------- ### Async Main Function with async-std Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Example of initializing an async content getter using async-std's runtime. ```rust #[async_std::main] async fn main() { let content = AsyncSCShareableContent::get().await.unwrap(); } ``` -------------------------------- ### Concurrent Operations Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Demonstrates how to perform multiple asynchronous queries for screen content concurrently using tokio::join!. ```APIDOC ## Concurrent Operations The async API allows concurrent operations without blocking: ```rust #[tokio::main] async fn main() -> Result<(), Box> { use screencapturekit::async_api::AsyncSCShareableContent; // Query content concurrently let (all_content, on_screen_only) = tokio::join!( AsyncSCShareableContent::get(), AsyncSCShareableContent::create() .with_on_screen_windows_only(true) .get(), ); let content = all_content?; let visible_content = on_screen_only?; println!("Total windows: {}", content.windows().len()); println!("Visible windows: {}", visible_content.windows().len()); Ok(()) } ``` ``` -------------------------------- ### Create New SCStreamConfiguration Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStreamConfiguration.md Initializes a new SCStreamConfiguration with default settings for minimal video and no audio. This is the starting point for all configuration chains. ```rust pub fn new() -> Self ``` -------------------------------- ### FFI Naming Convention Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/swift-bridge/README.md Illustrates the FFI naming convention used for symbols, following a '__' pattern. ```text __ ``` ```text sc_stream_start_capture, cv_pixel_buffer_lock_base_address ``` -------------------------------- ### SCStreamConfiguration::new Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStreamConfiguration.md Creates a new SCStreamConfiguration instance with default settings. This is the starting point for building a custom capture configuration. ```APIDOC ## SCStreamConfiguration::new ### Description Creates a new configuration with default settings (minimal video, no audio). ### Returns `Self` - A new `SCStreamConfiguration` instance. ### Example ```rust use screencapturekit::prelude::* let config = SCStreamConfiguration::new() .with_width(1920) .with_height(1080) .with_pixel_format(PixelFormat::BGRA); ``` ``` -------------------------------- ### Get Default SCShareableContent Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves all available displays and windows for screen capture. Requires screen recording permission. ```rust use screencapturekit::prelude::*; fn main() -> Result<(), Box> { let content = SCShareableContent::get()?; println!("Displays: {}", content.displays().len()); println!("Windows: {}", content.windows().len()); Ok(()) } ``` -------------------------------- ### Get Content Snapshot Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves all displays, windows, and applications in a single FFI call. Recommended for enumerating large window sets for performance benefits. ```rust if let Some(ContentSnapshot { displays, windows, applications }) = content.snapshot() { for window in windows { if let Some(app) = window.owning_app_index.and_then(|i| applications.get(i)) { println!("{}: {}", app.application_name, window.title); } } } ``` -------------------------------- ### Create Filter for Full Display Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCContentFilter.md Builds an SCContentFilter to capture the entire screen. This example selects the first available display and excludes no windows. ```rust let content = SCShareableContent::get()?; let display = &content.displays()[0]; let filter = SCContentFilter::create() .with_display(display) .with_excluding_windows(&[]) .build(); ``` -------------------------------- ### Basic Screen Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/README.md A minimal example demonstrating the four core steps: listing shareable content, building a content filter, configuring the stream, and adding an output handler. Requires 'Send + Sync' for output handlers. ```rust use screencapturekit::prelude::*; struct Handler; impl SCStreamOutputTrait for Handler { fn did_output_sample_buffer(&self, sample: CMSampleBuffer, _: SCStreamOutputType) { println!("📹 frame @ {:?}", sample.presentation_timestamp()); } } fn main() -> Result<(), Box> { let content = SCShareableContent::get()?; 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) .with_pixel_format(PixelFormat::BGRA); let mut stream = SCStream::new(&filter, &config); stream.add_output_handler(Handler, SCStreamOutputType::Screen); stream.start_capture()?; std::thread::sleep(std::time::Duration::from_secs(5)); stream.stop_capture()?; Ok(()) } ``` -------------------------------- ### Complete Async Screen Capture Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Demonstrates how to capture screen content asynchronously, select a display, configure the stream, and iterate through captured frames. Requires the 'async' feature flag. ```rust #[cfg(feature = "async")] async fn capture_example() -> Result<(), Box> { use screencapturekit::async_api::{AsyncSCShareableContent, AsyncSCStream}; use screencapturekit::prelude::*; // Get content asynchronously let content = AsyncSCShareableContent::create() .with_on_screen_windows_only(true) .get() .await?; // Select first display let display = content.displays() .into_iter() .next() .ok_or("No displays")?; // Create filter and config let filter = SCContentFilter::create() .with_display(&display) .with_excluding_windows(&[]) .build(); let config = SCStreamConfiguration::new() .with_width(1920) .with_height(1080) .with_pixel_format(PixelFormat::BGRA); // Create and start stream let mut stream = AsyncSCStream::new( &filter, &config, 30, SCStreamOutputType::Screen ); stream.start_capture()?; // Iterate asynchronously let mut count = 0; while let Some(sample) = stream.next().await { count += 1; let pts = sample.presentation_timestamp(); println!("Frame {}: {:.3}s", count, pts.to_seconds()); if count >= 100 { break; } } stream.stop_capture()?; println!("Captured {} frames", count); Ok(()) } ``` -------------------------------- ### Handle RuntimeError During Stream Start Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/errors.md This snippet demonstrates how to catch a RuntimeError when starting a capture stream. It includes a basic recovery strategy of waiting and retrying. ```rust match stream.start_capture() { Err(SCError::SCStreamError { code: SCStreamErrorCode::RuntimeError, message }) => { eprintln!("Runtime error: {:?}", message); // Attempt recovery: wait and retry std::thread::sleep(Duration::from_millis(500)); let _ = stream.start_capture(); } _ => {} } ``` -------------------------------- ### Async Create with Options Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Initiates the creation of shareable screen content with options, allowing for configuration before retrieval. ```APIDOC ## Async Create with Options ### Description Initiates the creation of shareable screen content with options, allowing for configuration before retrieval. ### Method `fn create() -> AsyncSCShareableContentOptions` ### Returns `AsyncSCShareableContentOptions` - An object to configure options before calling `.get().await`. ### Example ```rust #[cfg(feature = "async")] { let content = AsyncSCShareableContent::create() .with_on_screen_windows_only(true) .get() .await?; } ``` ``` -------------------------------- ### Audio + Video Capture Configuration Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStreamConfiguration.md Set up stream configuration to capture both audio and video. This example specifies a 720p resolution, enables audio capture, and sets the sample rate and channel count for audio. ```rust let config = SCStreamConfiguration::new() .with_width(1280) .with_height(720) .with_captures_audio(true) .with_sample_rate(48_000) .with_channel_count(2); ``` -------------------------------- ### Set Up Video and Audio Capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStream.md Demonstrates how to configure an SCStream to capture both video and audio simultaneously. This involves creating the stream with audio enabled and adding separate output handlers for screen and audio data. ```rust let mut stream = SCStream::new(&filter, &config.with_captures_audio(true)); stream.add_output_handler( |sample, _| { /* video frames */ }, SCStreamOutputType::Screen ); stream.add_output_handler( |sample, _| { /* audio samples */ }, SCStreamOutputType::Audio ); stream.start_capture()?; ``` -------------------------------- ### Run All Benchmarks Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/docs/BENCHMARKS.md Execute all available performance benchmarks using Cargo. Ensure you have screen recording permissions and a display connected. ```bash cargo bench ``` -------------------------------- ### start_capture Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCStream.md Starts the screen capture session. This method initiates the capture process and should be called before attempting to receive frames. It returns Ok(()) on success or an SCError if the stream configuration is invalid or capture permission is denied. ```APIDOC ## start_capture ### Description Starts the screen capture session. This method initiates the capture process and should be called before attempting to receive frames. It returns Ok(()) on success or an SCError if the stream configuration is invalid or capture permission is denied. ### Method Rust Function ### Parameters None ### Returns `Ok(())` on success, `Err(SCError)` on failure. ### Throws `SCError::SCStreamError` if stream configuration is invalid or capture permission is denied. ### Example ```rust stream.start_capture()?; std::thread::sleep(Duration::from_secs(5)); stream.stop_capture()?; ``` ``` -------------------------------- ### Get Displays Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves a vector of all available displays, both physical and virtual. ```APIDOC ## get_displays ### Description Retrieves a vector of available displays (physical and virtual). ### Method ```rust pub fn displays(&self) -> Vec ``` ### Returns - `Vec`: A vector containing information about each display. ``` -------------------------------- ### Basic Screen Capture Workflow Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/README.md This snippet demonstrates the 5-step process for basic screen capture using SCStream. It covers listing content, creating a filter, configuring stream settings, adding an output handler, and starting the capture. ```rust let content = SCShareableContent::get()?; 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) .with_pixel_format(PixelFormat::BGRA); let mut stream = SCStream::new(&filter, &config); stream.add_output_handler( |sample, _type| println!("Frame!"), SCStreamOutputType::Screen ); stream.start_capture()?; ``` -------------------------------- ### Error Reference Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/COMPLETION_SUMMARY.txt Guide to error codes, their triggers, and suggested fixes. ```APIDOC ## errors.md ### Description Reference for error handling, detailing 10+ error codes, their causes, and recommended solutions. ``` -------------------------------- ### Get Image Dimensions Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/ScreenshotManager.md Retrieves the width and height of the captured image in pixels. ```APIDOC ## Get Image Dimensions ### Description Retrieves the width and height of the captured image in pixels. ### Method `width(&self)` and `height(&self)` ### Parameters None ### Returns - `usize` - Image dimensions in pixels. ### Example ```rust let w = image.width(); let h = image.height(); println!("Image: {}x{}", w, h); ``` ``` -------------------------------- ### SCRecordingOutput::new Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/RecordingOutput.md Creates a new SCRecordingOutput instance with the specified configuration. This is the entry point for setting up where and how the recording will be saved. ```APIDOC ## SCRecordingOutput::new ### Description Creates a new `SCRecordingOutput` instance with the specified configuration. This is the entry point for setting up where and how the recording will be saved. ### Signature ```rust #[cfg(feature = "macos_15_0")] pub fn new(config: &SCRecordingOutputConfiguration) -> Option ``` ### Parameters #### Path Parameters - **config** (`&SCRecordingOutputConfiguration`) - Yes - Recording settings ### Returns - `Some(SCRecordingOutput)` if created successfully, `None` if configuration is invalid. ### Example ```rust #[cfg(feature = "macos_15_0")] { let config = SCRecordingOutputConfiguration::new() .with_output_url(&PathBuf::from("/tmp/recording.mp4")) .with_video_codec(SCRecordingOutputCodec::H264) .with_output_file_type(SCRecordingOutputFileType::MP4); if let Some(recording) = SCRecordingOutput::new(&config) { // Use recording output } else { eprintln!("Failed to create recording output"); } } ``` ``` -------------------------------- ### Get Windows Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves a vector of all capturable windows, including off-screen windows. ```APIDOC ## get_windows ### Description Retrieves a vector of all capturable windows. By default, this includes off-screen windows. ### Method ```rust pub fn windows(&self) -> Vec ``` ### Returns - `Vec`: A vector containing information about each capturable window. ### Notes - Includes off-screen windows by default (filter with options). - Windows from all applications, not just the frontmost. - Owned windows are available via `window.owning_application()`. ``` -------------------------------- ### Get Running Applications Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves a vector of running applications whose content can be captured. ```APIDOC ## get_applications ### Description Retrieves a vector of running applications whose content can be captured. ### Method ```rust pub fn applications(&self) -> Vec ``` ### Returns - `Vec`: A vector containing information about each running application. ``` -------------------------------- ### Get Content Asynchronously Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Retrieves SCShareableContent asynchronously. This method is non-blocking and works with any async executor. ```APIDOC ## Get Content Asynchronously ### Description Retrieves SCShareableContent asynchronously. This method is non-blocking and works with any async executor. ### Method `async fn get() -> Result` ### Returns Future resolving to `Result`. ### Example ```rust #[cfg(feature = "async")] use screencapturekit::async_api::AsyncSCShareableContent; #[tokio::main] async fn main() -> Result<(), Box> { // Non-blocking; works with any executor let content = AsyncSCShareableContent::get().await?; println!("Displays: {}", content.displays().len()); Ok(()) } ``` ``` -------------------------------- ### Get Available Displays Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Iterates through and prints information about each available display. Requires SCShareableContent to be initialized. ```rust let content = SCShareableContent::get()?; for display in content.displays() { println!( "Display {}: {}x{} (scale: {:.1}x)", display.display_id(), display.width(), display.height(), display.frame().size.width as f64 / display.width() as f64 ); } ``` -------------------------------- ### SCRecordingOutputConfiguration Output URL Round-trip Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/COVERAGE.md Demonstrates the round-trip capability for setting and getting the output URL in SCRecordingOutputConfiguration. ```rust output_url() ``` -------------------------------- ### Handle Sample Buffers by Type Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/types.md Demonstrates how to process different types of sample buffers (video, audio, microphone) within the `did_output_sample_buffer` callback. ```rust impl SCStreamOutputTrait for MyHandler { fn did_output_sample_buffer(&self, sample: CMSampleBuffer, of_type: SCStreamOutputType) { match of_type { SCStreamOutputType::Screen => { /* process video frame */ }, SCStreamOutputType::Audio => { /* process audio samples */ }, #[cfg(feature = "macos_15_0")] SCStreamOutputType::Microphone => { /* process mic input */ }, _ => {} } } } ``` -------------------------------- ### Create with Options (Async Builder) Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Initiates an asynchronous content retrieval process using a builder pattern for customization. ```APIDOC ## Create with Options (Async Builder) ### Description Initiates an asynchronous content retrieval process using a builder pattern for customization. ### Method `fn create() -> AsyncSCShareableContentOptions` ### Returns Async builder for customized content retrieval. ### Chaining Methods | Method | Type | Description | |--------|------|-------------| | `.with_on_screen_windows_only(bool)` | Builder | Filter to visible windows only | | `.with_exclude_desktop_windows(bool)` | Builder | Exclude desktop background | | `.get()` | Future | Execute the query | ### Example ```rust let content = AsyncSCShareableContent::create() .with_on_screen_windows_only(true) .with_exclude_desktop_windows(true) .get() .await?; ``` ``` -------------------------------- ### Get Image Dimensions Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/ScreenshotManager.md Retrieves the width and height of a captured CGImage in pixels. This is useful for understanding the dimensions of the screenshot. ```rust let w = image.width(); let h = image.height(); println!("Image: {}x{}", w, h); ``` -------------------------------- ### Get Decode Timestamp from CMSampleBuffer Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/CMSampleBuffer.md Retrieve the decode timestamp (DTS) for a sample. Usually the same as PTS for screen capture. ```rust let dts = sample.decode_timestamp(); ``` -------------------------------- ### Get Current Process Content Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves shareable content for the current process, available on macOS 14.4 and later. ```APIDOC ## get_current_process_content ### Description Retrieves `SCShareableContent` for the current process if it has shareable content. ### Method ```rust #[cfg(feature = "macos_14_4")] pub fn current_process_content(&self) -> Option ``` ### Returns - `Option`: `Some(SCShareableContent)` if the current process has shareable content, `None` otherwise. ### Requires - Feature flag `macos_14_4` ``` -------------------------------- ### SCStreamConfiguration Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/COMPLETION_SUMMARY.txt Details on the configuration builder for setting up video and audio capture parameters. ```APIDOC ## SCStreamConfiguration.md ### Description Enables building and customizing stream configurations, including video and audio settings. ### Modules Covered - screencapturekit::stream ``` -------------------------------- ### Configure Stream with PixelFormat Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/types.md Example of setting the pixel format for a stream configuration. BGRA is recommended for optimal GPU performance. ```rust let config = SCStreamConfiguration::new() .with_pixel_format(PixelFormat::BGRA); ``` -------------------------------- ### Async Error Handling Example Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md Handles potential errors during asynchronous content retrieval, including permission and stream-specific errors. ```rust match AsyncSCShareableContent::get().await { Ok(content) => { /* use content */ }, Err(SCError::PermissionError) => eprintln!("Permission denied"), Err(SCError::StreamError(msg)) => eprintln!("Error: {}", msg), Err(e) => eprintln!("Other error: {e}"), } ``` -------------------------------- ### Build Swift Project Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/swift-bridge/README.md Command to build the Swift project in release mode, typically executed by build.rs. ```bash swift build -c release ``` -------------------------------- ### Build SCContentFilter with Specific Window Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCContentFilter.md Constructs a filter to capture only a single, specified window. This example finds a window by its title. ```rust let content = SCShareableContent::get()?; let window = content.windows() .into_iter() .find(|w| w.title().as_deref() == Some("Safari")) .ok_or("Window not found")?; let filter = SCContentFilter::create() .with_window(&window) .build(); ``` -------------------------------- ### Use System Default Queue Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/DispatchQueue.md Demonstrates how to use the system's default dispatch queue for stream output handlers by passing `None`. This is a convenient option when custom queue management is not required. ```rust stream.add_output_handler_with_queue( MyHandler, SCStreamOutputType::Screen, None // System default queue ); ``` -------------------------------- ### Separate Queues for Video and Audio Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/DispatchQueue.md Demonstrates how to use separate custom queues for video and audio streams to manage their processing priorities independently. ```APIDOC ## Separate Queues for Video and Audio ### Description Demonstrates how to use separate custom queues for video and audio streams to manage their processing priorities independently. ### Example ```rust use screencapturekit::dispatch_queue::{DispatchQueue, DispatchQoS}; let video_queue = DispatchQueue::new("com.myapp.video", DispatchQoS::UserInteractive); let audio_queue = DispatchQueue::new("com.myapp.audio", DispatchQoS::UserInitiated); let mut stream = SCStream::new(&filter, &config); // Video frames on high-priority queue stream.add_output_handler_with_queue( VideoHandler, SCStreamOutputType::Screen, Some(&video_queue) ); // Audio on separate queue stream.add_output_handler_with_queue( AudioHandler, SCStreamOutputType::Audio, Some(&audio_queue) ); stream.start_capture()?; ``` ``` -------------------------------- ### SCContentFilter::create Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCContentFilter.md Creates a new, unconfigured filter builder for SCContentFilter. This is the starting point for fluently constructing capture filters. ```APIDOC ## SCContentFilter::create ### Description Creates a new, unconfigured filter builder for SCContentFilter. ### Returns `Self` - A new, unconfigured filter builder. ### Example ```rust use screencapturekit::prelude::* let filter = SCContentFilter::create() .with_display(&display) .with_excluding_windows(&[]) .build(); ``` ``` -------------------------------- ### Stream Creation Migration (0.x to 1.0) Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/docs/MIGRATION.md Illustrates the changes in stream creation between 0.x and 1.0. The 1.0 version requires adding output handlers separately after stream initialization. ```rust use screencapturekit::sc_stream::UnsafeSCStream; let stream = UnsafeSCStream::new(filter, config, handler); stream.start_capture(); ``` ```rust use screencapturekit::prelude::*; let mut stream = SCStream::new(&filter, &config); stream.add_output_handler(handler, SCStreamOutputType::Screen); stream.start_capture()?; ``` -------------------------------- ### Create SCContentFilter Builder Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCContentFilter.md Initializes a new, unconfigured filter builder. Use this as the starting point for constructing a capture filter. ```rust pub fn create() -> Self ``` -------------------------------- ### Import Common Types from screencapturekit::prelude Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/README.md Use the prelude module to import commonly used types such as SCStream, SCStreamConfiguration, SCContentFilter, SCShareableContent, CMSampleBuffer, PixelFormat, and SCStreamOutputType. ```rust use screencapturekit::prelude::*; // Provides: SCStream, SCStreamConfiguration, SCContentFilter, // SCShareableContent, CMSampleBuffer, PixelFormat, SCStreamOutputType, etc. ``` -------------------------------- ### Configure Screen Capture with Version-Specific Options Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/README.md Demonstrates how to configure screen capture settings, including version-specific options gated by feature flags. Use this to conditionally apply settings based on the macOS version. ```rust let mut config = SCStreamConfiguration::new().with_width(1920).with_height(1080); #[cfg(feature = "macos_14_2")] { config.set_ignores_shadows_single_window(true); config.set_includes_child_windows(false); } ``` -------------------------------- ### Get Duration from CMSampleBuffer Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/CMSampleBuffer.md Retrieve the duration of a sample, representing how long the frame is valid. Useful for calculating frame rate. ```rust let duration = sample.duration(); let frame_rate = duration.timescale as f64 / duration.value as f64; println!("Frame duration: {:.3}ms", duration.to_seconds() * 1000.0); ``` -------------------------------- ### Profile GPU Performance Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/docs/BENCHMARKS.md Employ xcrun xctrace with the 'Metal System Trace' template for detailed GPU performance analysis during benchmarks. ```bash # GPU profiling xcrun xctrace record --template 'Metal System Trace' --launch -- cargo bench ``` -------------------------------- ### Get All Capturable Windows Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/SCShareableContent.md Retrieves a list of all capturable windows and prints their titles. Note that off-screen windows are included by default. ```rust let content = SCShareableContent::get()?; for window in content.windows() { if let Some(title) = window.title() { println!("Window: {}", title); } } ``` -------------------------------- ### Custom Executor Integration Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/api-reference/AsyncAPI.md The async API is designed to work with any executor that implements futures::Executor without special setup. ```rust // Works with any executor that implements futures::Executor ``` -------------------------------- ### Handling FailedToStart Error Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/errors.md Shows how to handle a `FailedToStart` error, checking the error message for specific causes like permission issues and printing relevant advice. ```rust match stream.start_capture() { Ok(()) => { /* started */ }, Err(SCError::SCStreamError { code: SCStreamErrorCode::FailedToStart, message }) => { eprintln!("Failed to start: {:?}", message); if let Some(msg) = message { if msg.contains("permission") { eprintln!("Check System Settings for screen recording permission"); } } } Err(e) => eprintln!("Error: {e}") } ``` -------------------------------- ### Configure Content Sharing Picker (macOS 14.0+) Source: https://github.com/doom-fish/screencapturekit-rs/blob/main/_autodocs/configuration.md Initializes and shows the content sharing picker configuration. Requires the `macos_14_0` feature. Handles user selection, cancellation, or errors. ```rust #[cfg(feature = "macos_14_0")] { let config = SCContentSharingPickerConfiguration::new(); SCContentSharingPicker::show(&config, |outcome| { match outcome { SCPickerOutcome::Picked(result) => { /* use result */ }, SCPickerOutcome::Cancelled => { /* user cancelled */ }, SCPickerOutcome::Error(e) => { /* error */ }, } })?; } ```