Struct Capture

Source
pub struct Capture {
    pub(crate) video_encoder: Arc<Mutex<dyn VideoEncoder + Send>>,
    pub(crate) audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>,
    pub(crate) stop_flag: Arc<AtomicBool>,
    pub(crate) pause_flag: Arc<AtomicBool>,
    pub(crate) egl_ctx: Arc<EglContext>,
    pub(crate) worker_handles: Vec<JoinHandle<()>>,
    pub(crate) pw_video_terminate_tx: Sender<Terminate>,
    pub(crate) pw_audio_terminate_tx: Option<Sender<Terminate>>,
}
Expand description

Main capture instance for recording screen content and audio.

Capture provides methods to control the recording process, retrieve encoded frames, and manage the capture lifecycle.

§Examples

use waycap_rs::{CaptureBuilder, QualityPreset, VideoEncoder};

// Create a capture instance
let mut capture = CaptureBuilder::new()
    .with_quality_preset(QualityPreset::Medium)
    .with_video_encoder(VideoEncoder::Vaapi)
    .build()
    .expect("Failed to create capture");

// Start the capture
capture.start().expect("Failed to start capture");

// Get video receiver
let video_receiver = capture.take_video_receiver();

// Process Frames
while let Some(encoded_frame) = video_receiver.try_pop() {
    println!("Received an encoded frame");
}

Fields§

§video_encoder: Arc<Mutex<dyn VideoEncoder + Send>>§audio_encoder: Option<Arc<Mutex<dyn AudioEncoder + Send>>>§stop_flag: Arc<AtomicBool>§pause_flag: Arc<AtomicBool>§egl_ctx: Arc<EglContext>§worker_handles: Vec<JoinHandle<()>>§pw_video_terminate_tx: Sender<Terminate>§pw_audio_terminate_tx: Option<Sender<Terminate>>

Implementations§

Source§

impl Capture

Source

pub(crate) fn new( video_encoder_type: VideoEncoderType, audio_encoder_type: AudioEncoderType, quality: QualityPreset, include_cursor: bool, include_audio: bool, target_fps: u64, ) -> Result<Self>

Source

pub fn start(&mut self) -> Result<()>

Enables capture streams to send their frames to their encoders

Source

pub fn pause(&mut self) -> Result<()>

Temporarily stops the recording by blocking frames from being sent to the encoders

Source

pub fn finish(&mut self) -> Result<()>

Stop recording and drain the encoders of any last frames they have in their internal buffers

Source

pub fn reset(&mut self) -> Result<()>

Resets the encoder states so we can resume encoding from within this same session

Source

pub fn close(&mut self) -> Result<()>

Close the connection. Once called the struct cannot be re-used and must be re-built with the CaptureBuilder to record again. If your goal is to temporarily stop recording use Self::pause or Self::finish + Self::reset

Source

pub fn take_video_receiver(&mut self) -> HeapCons<EncodedVideoFrame>

Take ownership of the ring buffer which will supply you with encoded video frame data

IMPORTANT

This gives you ownership of the buffer so this can only be called once

Source

pub fn take_audio_receiver(&mut self) -> Result<HeapCons<EncodedAudioFrame>>

Take ownership of the ring buffer which will supply you with encoded audio frame data

IMPORTANT

This gives you ownership of the buffer so this can only be called once

Source

pub fn with_video_encoder<F, R>(&self, f: F) -> R
where F: FnOnce(&Option<Video>) -> R,

Perform an action with the video encoder

§Examples
let mut output = ffmpeg::format::output(&filename)?;

capture.with_video_encoder(|enc| {
    if let Some(video_encoder) = enc {
        let mut video_stream = output.add_stream(video_encoder.codec().unwrap()).unwrap();
        video_stream.set_time_base(video_encoder.time_base());
        video_stream.set_parameters(video_encoder);
    }
});
output.write_header()?;
Source

pub fn with_audio_encoder<F, R>(&self, f: F) -> R
where F: FnOnce(&Option<Audio>) -> R,

Perform an action with the audio encoder

§Examples
let mut output = ffmpeg::format::output(&filename)?;
capture.with_audio_encoder(|enc| {
    if let Some(audio_encoder) = enc {
        let mut audio_stream = output.add_stream(audio_encoder.codec().unwrap()).unwrap();
        audio_stream.set_time_base(audio_encoder.time_base());
        audio_stream.set_parameters(audio_encoder);

    }
});
output.write_header()?;

Trait Implementations§

Source§

impl Drop for Capture

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V