Skip to main content

ProgressCallback

Trait ProgressCallback 

Source
pub trait ProgressCallback: Send {
    // Required method
    fn on_progress(&mut self, progress: &Progress);

    // Provided method
    fn should_cancel(&self) -> bool { ... }
}
Expand description

Progress callback trait for monitoring encoding progress.

Implement this trait to receive real-time encoding progress updates and optionally support encoding cancellation.

§Examples

use ff_encode::{Progress, ProgressCallback};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

struct MyProgressHandler {
    cancelled: Arc<AtomicBool>,
}

impl ProgressCallback for MyProgressHandler {
    fn on_progress(&mut self, progress: &Progress) {
        println!("Encoded {} frames at {:.1} fps",
            progress.frames_encoded,
            progress.current_fps
        );
    }

    fn should_cancel(&self) -> bool {
        self.cancelled.load(Ordering::Relaxed)
    }
}

Required Methods§

Source

fn on_progress(&mut self, progress: &Progress)

Called when encoding progress is updated.

This method is called periodically during encoding to report progress. The frequency of calls depends on the encoding speed and frame rate.

§Arguments
  • progress - Current encoding progress information

Provided Methods§

Source

fn should_cancel(&self) -> bool

Check if encoding should be cancelled.

The encoder will check this method periodically during encoding. Return true to request cancellation of the encoding process.

§Returns

true to cancel encoding, false to continue

§Default Implementation

The default implementation returns false (never cancel).

Implementors§

Source§

impl<F> ProgressCallback for F
where F: FnMut(&Progress) + Send,

Implement ProgressCallback for closures.

This allows using simple closures as progress callbacks without needing to define a custom struct implementing the trait.