SCStream

Struct SCStream 

Source
pub struct SCStream { /* private fields */ }
Expand description

SCStream is a lightweight wrapper around the Swift SCStream instance. It provides direct FFI access to ScreenCaptureKit functionality.

This is the primary and only implementation of SCStream in v1.0+. All ScreenCaptureKit operations go through Swift FFI bindings.

§Examples

use screencapturekit::prelude::*;

// Get shareable content
let content = SCShareableContent::get()?;
let display = &content.displays()[0];

// Create filter and configuration
let filter = SCContentFilter::builder()
    .display(display)
    .exclude_windows(&[])
    .build();
let mut config = SCStreamConfiguration::default();
config.set_width(1920);
config.set_height(1080);

// Create and start stream
let mut stream = SCStream::new(&filter, &config);
stream.start_capture()?;

// ... capture frames ...

stream.stop_capture()?;

Implementations§

Source§

impl SCStream

Source

pub fn new( filter: &SCContentFilter, configuration: &SCStreamConfiguration, ) -> Self

Create a new stream with a content filter and configuration

§Panics

Panics if the Swift bridge returns a null stream pointer.

§Examples
use screencapturekit::prelude::*;

let content = SCShareableContent::get()?;
let display = &content.displays()[0];
let filter = SCContentFilter::builder()
    .display(display)
    .exclude_windows(&[])
    .build();
let config = SCStreamConfiguration::default();

let stream = SCStream::new(&filter, &config);
Source

pub fn new_with_delegate( filter: &SCContentFilter, configuration: &SCStreamConfiguration, _delegate: impl SCStreamDelegateTrait, ) -> Self

Source

pub fn add_output_handler( &mut self, handler: impl SCStreamOutputTrait + 'static, of_type: SCStreamOutputType, ) -> Option<usize>

Add an output handler to receive captured frames

§Arguments
  • handler - The handler to receive callbacks. Can be:
    • A struct implementing SCStreamOutputTrait
    • A closure |CMSampleBuffer, SCStreamOutputType| { ... }
  • of_type - The type of output to receive (Screen, Audio, or Microphone)
§Returns

Returns Some(handler_id) on success, None on failure. The handler ID can be used with remove_output_handler.

§Examples

Using a struct:

use screencapturekit::prelude::*;

struct MyHandler;
impl SCStreamOutputTrait for MyHandler {
    fn did_output_sample_buffer(&self, _sample: CMSampleBuffer, _of_type: SCStreamOutputType) {
        println!("Got frame!");
    }
}

let mut stream = SCStream::new(&filter, &config);
stream.add_output_handler(MyHandler, SCStreamOutputType::Screen);

Using a closure:

use screencapturekit::prelude::*;

let mut stream = SCStream::new(&filter, &config);
stream.add_output_handler(
    |_sample, _type| println!("Got frame!"),
    SCStreamOutputType::Screen
);
Source

pub fn add_output_handler_with_queue( &mut self, handler: impl SCStreamOutputTrait + 'static, of_type: SCStreamOutputType, queue: Option<&DispatchQueue>, ) -> Option<usize>

Add an output handler with a custom dispatch queue

This allows controlling which thread/queue the handler is called on.

§Arguments
  • handler - The handler to receive callbacks
  • of_type - The type of output to receive
  • queue - Optional custom dispatch queue for callbacks
§Panics

Panics if the internal handler registry mutex is poisoned.

§Examples
use screencapturekit::prelude::*;
use screencapturekit::dispatch_queue::{DispatchQueue, DispatchQoS};

let mut stream = SCStream::new(&filter, &config);
let queue = DispatchQueue::new("com.myapp.capture", DispatchQoS::UserInteractive);

stream.add_output_handler_with_queue(
    |_sample, _type| println!("Got frame on custom queue!"),
    SCStreamOutputType::Screen,
    Some(&queue)
);
Source

pub fn remove_output_handler( &mut self, id: usize, _of_type: SCStreamOutputType, ) -> bool

Remove an output handler

§Arguments
  • id - The handler ID returned from add_output_handler
  • of_type - The type of output the handler was registered for
§Panics

Panics if the internal handler registry mutex is poisoned.

§Returns

Returns true if the handler was found and removed, false otherwise.

Source

pub fn start_capture(&self) -> Result<(), SCError>

Start capturing screen content

This method blocks until the capture operation completes or fails.

§Errors

Returns SCError::CaptureStartFailed if the capture fails to start.

Source

pub fn stop_capture(&self) -> Result<(), SCError>

Stop capturing screen content

This method blocks until the capture operation completes or fails.

§Errors

Returns SCError::CaptureStopFailed if the capture fails to stop.

Source

pub fn update_configuration( &self, configuration: &SCStreamConfiguration, ) -> Result<(), SCError>

Update the stream configuration

This method blocks until the configuration update completes or fails.

§Errors

Returns SCError::StreamError if the configuration update fails.

Source

pub fn update_content_filter( &self, filter: &SCContentFilter, ) -> Result<(), SCError>

Update the content filter

This method blocks until the filter update completes or fails.

§Errors

Returns SCError::StreamError if the filter update fails.

Trait Implementations§

Source§

impl Clone for SCStream

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SCStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SCStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for SCStream

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for SCStream

Source§

impl Sync for SCStream

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.