AsyncSCStream

Struct AsyncSCStream 

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

Async wrapper for SCStream with integrated frame iteration

Provides async methods for stream lifecycle and frame iteration. Executor-agnostic - works with any async runtime.

§Examples

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::builder().display(display).exclude_windows(&[]).build();
let mut config = SCStreamConfiguration::default();
config.set_width(1920);
config.set_height(1080);

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

// Process frames asynchronously
while let Some(frame) = stream.next().await {
    println!("Got frame!");
}

Implementations§

Source§

impl AsyncSCStream

Source

pub fn new( filter: &SCContentFilter, config: &SCStreamConfiguration, buffer_capacity: usize, output_type: SCStreamOutputType, ) -> Self

Create a new async stream

§Arguments
  • filter - Content filter specifying what to capture
  • config - Stream configuration
  • buffer_capacity - Max frames to buffer (oldest dropped when full)
  • output_type - Type of output (Screen, Audio, Microphone)
Source

pub fn next(&self) -> NextSample<'_>

Get the next sample buffer asynchronously

Returns None when the stream is closed.

Source

pub fn try_next(&self) -> Option<CMSampleBuffer>

Try to get a sample without waiting

Source

pub fn is_closed(&self) -> bool

Check if the stream has been closed

Source

pub fn buffered_count(&self) -> usize

Get the number of buffered samples

Source

pub fn clear_buffer(&self)

Clear all buffered samples

Source

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

Start capture (synchronous - returns immediately)

§Errors

Returns an error if capture fails to start.

Source

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

Stop capture (synchronous - returns immediately)

§Errors

Returns an error if capture fails to stop.

Source

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

Update stream configuration

§Errors

Returns an error if the update fails.

Source

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

Update content filter

§Errors

Returns an error if the update fails.

Source

pub fn inner(&self) -> &SCStream

Get a reference to the underlying stream

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> 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, 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.