Skip to main content

TaskImpl

Trait TaskImpl 

Source
pub trait TaskImpl: Send + 'static {
    type Item: Send + 'static;

    // Required methods
    fn obj(&self) -> &impl IsA<Object>;
    fn try_next(
        &mut self,
    ) -> impl Future<Output = Result<Self::Item, FlowError>> + Send;
    fn handle_item(
        &mut self,
        _item: Self::Item,
    ) -> impl Future<Output = Result<(), FlowError>> + Send;

    // Provided methods
    fn prepare(
        &mut self,
    ) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn unprepare(&mut self) -> impl Future<Output = ()> + Send { ... }
    fn start(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn pause(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn flush_start(
        &mut self,
    ) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn flush_stop(
        &mut self,
    ) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn stop(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send { ... }
    fn handle_loop_error(
        &mut self,
        err: FlowError,
    ) -> impl Future<Output = Trigger> + Send { ... }
    fn handle_action_error(
        &mut self,
        trigger: Trigger,
        state: TaskState,
        err: ErrorMessage,
    ) -> impl Future<Output = Trigger> + Send { ... }
}
Expand description

Implementation trait for Tasks.

Defines implementations for state transition actions and error handlers.

Required Associated Types§

Source

type Item: Send + 'static

Required Methods§

Source

fn obj(&self) -> &impl IsA<Object>

Source

fn try_next( &mut self, ) -> impl Future<Output = Result<Self::Item, FlowError>> + Send

Tries to retrieve the next item to process.

With Self::handle_item, this is one of the two Task loop functions. They are executed in a loop in the Started state.

Function try_next is awaited at the beginning of each iteration, and can be cancelled at await point if a state transition is requested.

If Ok(item) is returned, the iteration calls Self::handle_item with said Item.

If Err(..) is returned, the iteration calls Self::handle_loop_error.

Source

fn handle_item( &mut self, _item: Self::Item, ) -> impl Future<Output = Result<(), FlowError>> + Send

Does whatever needs to be done with the item.

With Self::try_next, this is one of the two Task loop functions. They are executed in a loop in the Started state.

Function handle_item asynchronously processes an item previously retrieved by Self::try_next. Processing is guaranteed to run to completion even if a state transition is requested.

If Err(..) is returned, the iteration calls Self::handle_loop_error.

Provided Methods§

Source

fn prepare(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn unprepare(&mut self) -> impl Future<Output = ()> + Send

Source

fn start(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn pause(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn flush_start( &mut self, ) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn flush_stop( &mut self, ) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn stop(&mut self) -> impl Future<Output = Result<(), ErrorMessage>> + Send

Source

fn handle_loop_error( &mut self, err: FlowError, ) -> impl Future<Output = Trigger> + Send

Handles an error occurring during the execution of the Task loop.

This include errors returned by Self::try_next & Self::handle_item.

If the error is unrecoverable, implementations might use gst::Element::post_error_message and return Trigger::Error.

Otherwise, handle the error and return the requested Transition to recover.

Default behaviour depends on the err:

  • FlowError::Flushing -> Trigger::FlushStart.
  • FlowError::Eos -> Trigger::Stop.
  • Other FlowError -> Trigger::Error.
Source

fn handle_action_error( &mut self, trigger: Trigger, state: TaskState, err: ErrorMessage, ) -> impl Future<Output = Trigger> + Send

Handles an error occurring during the execution of a transition action.

This handler also catches errors returned by subtasks spawned by the transition action.

If the error is unrecoverable, implementations might use gst::Element::post_error_message and return Trigger::Error.

Otherwise, handle the error and return the recovering Trigger.

Default is to gst::error log and return Trigger::Error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§