Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder<S: DecoderState> { /* private fields */ }

Implementations§

Source§

impl Decoder<AwaitingOutputFormat>

Source

pub fn open(path: &Path) -> Result<Self, DecoderOpenError>

Source

pub fn set_output_format<F>( self, f: F, ) -> Result<Decoder<AwaitingOutputBuffers>>
where F: FnOnce(FormatBuilder<'_>) -> Result<()>,

Source§

impl Decoder<AwaitingOutputBuffers>

Source§

impl<OP: BufferHandles> Decoder<ReadyToDecode<OP>>

Source

pub fn set_poll_counter(self, poll_wakeups_counter: Arc<AtomicUsize>) -> Self

Source

pub fn start<P, InputDoneCb, DecoderEventCb, FormatChangedCb>( self, input_done_cb: InputDoneCb, decoder_event_cb: DecoderEventCb, set_capture_format_cb: FormatChangedCb, ) -> Result<Decoder<Decoding<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb>>, StartDecoderError>

Source§

impl<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb> Decoder<Decoding<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb>>
where OP: BufferHandles, P: HandlesProvider, InputDoneCb: InputDoneCallback<OP>, DecoderEventCb: DecoderEventCallback<P>, FormatChangedCb: FormatChangedCallback<P>,

Source

pub fn num_output_buffers(&self) -> usize

Source

pub fn get_output_format<O: TryFrom<v4l2_format>>(&self) -> Result<O, GFmtError>

Source

pub fn stop( self, ) -> Result<Vec<<Queue<Output, BuffersAllocated<OP>> as Stream>::Canceled>, StopError>

Stop the decoder.

This will stop any pending operation consume the decoder, which cannot be used anymore. To make sure all submitted encoded buffers have been processed, call the Decoder::drain method and wait for the output buffer with the LAST flag before calling this method.

TODO potential bug: the LAST buffer could also be the one signaling a DRC. We need another way to manage this? Probably a good idea to split into two properties of DQBuf.

Source

pub fn drain(&self, blocking: bool) -> Result<bool, DrainError>

Drain the decoder, i.e. make sure all its pending work is processed.

The blocking parameters decides whether this method is permitted to block: if true, then all the frames corresponding to the encoded buffers queued so far will have been emitted when this function returns. In this case the method will always return true to signal that drain has been completed.

If false, then the method may also return false to signal that drain has not completed yet. When this is the case, the client must look for a decoded frame with the LAST flag set, as this flag signals that this frame is the last one before the drain has completed.

Note that requesting a blocking drain can be hazardous if the current thread is responsible for e.g. submitting handles for decoded frames. It is easy to put the decoding pipeline in a deadlock situation.

The client can keep submitting buffers with encoded data as the drain is ongoing. They will be processed in order and their frames will come after the ones still in the pipeline. For a way to cancel all the pending jobs, see the Decoder::flush method.

Source

pub fn flush(&self) -> Result<(), FlushError>

Flush the decoder, i.e. try to cancel all pending work.

The canceled input buffers will be returned as CompletedInputBuffer::Canceled through the input done callback.

If a Decoder::drain operation was in progress, it is also canceled.

This function is blocking. When is returns, the frame decoded callback has been called for all pre-flush frames, and the decoder can accept new content to decode.

Source§

impl<'a, OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb> Decoder<Decoding<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb>>
where Self: GetFreeOutputBuffer<'a, OP, GetBufferError>, OP: BufferHandles, P: HandlesProvider, InputDoneCb: InputDoneCallback<OP>, DecoderEventCb: DecoderEventCallback<P>, FormatChangedCb: FormatChangedCallback<P>,

Source

pub fn num_queued_buffers(&self) -> usize

Returns the number of currently queued encoded buffers.

Source

pub fn get_buffer( &'a mut self, ) -> Result<<Self as OutputQueueableProvider<'a, OP>>::Queueable, GetBufferError>

Returns a V4L2 buffer to be filled with a frame to decode, waiting for one to be available if needed.

Contrary to Decoder::try_get_free_buffer(), this method will wait for a buffer to be available if needed.

Source

pub fn kick(&self) -> Result<(), DqBufError<V4l2BufferFromError>>

Kick the decoder and see if some input buffers fall as a result.

No, really. Completed input buffers are typically checked when calling Decoder::get_buffer (which is also the time when the input done callback is invoked), but this mechanism is not foolproof: if the client works with a limited set of input buffers and queues them all before an output frame can be produced, then the client has no more buffers to fill and thus no reason to call Decoder::get_buffer, resulting in the decoding process being blocked.

This method mitigates this problem by adding a way to check for completed input buffers and calling the input done callback without the need for new encoded content. It is suggested to call it from the thread that owns the decoder every time a decoded frame is produced. That way the client can recycle its input buffers and the decoding process does not get stuck.

Trait Implementations§

Source§

impl<'a, OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb> GetFreeOutputBuffer<'a, OP, GetBufferError> for Decoder<Decoding<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb>>
where Queue<Output, BuffersAllocated<OP>>: GetFreeOutputBuffer<'a, OP>, OP: BufferHandles, P: HandlesProvider, InputDoneCb: InputDoneCallback<OP>, DecoderEventCb: DecoderEventCallback<P>, FormatChangedCb: FormatChangedCallback<P>,

Let the decoder provide the buffers from the OUTPUT queue.

Source§

fn try_get_free_buffer(&'a self) -> Result<Self::Queueable, GetBufferError>

Returns a V4L2 buffer to be filled with a frame to decode if one is available.

This method will return None immediately if all the allocated buffers are currently queued.

Source§

impl<'a, OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb> OutputQueueableProvider<'a, OP> for Decoder<Decoding<OP, P, InputDoneCb, DecoderEventCb, FormatChangedCb>>
where Queue<Output, BuffersAllocated<OP>>: OutputQueueableProvider<'a, OP>, OP: BufferHandles, P: HandlesProvider, InputDoneCb: InputDoneCallback<OP>, DecoderEventCb: DecoderEventCallback<P>, FormatChangedCb: FormatChangedCallback<P>,

Auto Trait Implementations§

§

impl<S> Freeze for Decoder<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Decoder<S>
where S: RefUnwindSafe,

§

impl<S> Send for Decoder<S>
where S: Send,

§

impl<S> Sync for Decoder<S>
where S: Sync,

§

impl<S> Unpin for Decoder<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for Decoder<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for Decoder<S>
where S: UnwindSafe,

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.