1 //! High-level interface for a V4L2 video decoder. Currently only supports the
2 //! [stateful interface](https://www.kernel.org/doc/html/latest/userspace-api/media/v4l/dev-encoder.html).
3 use crate::{
4     device::queue::{
5         direction::{Capture, Output},
6         dqbuf::DqBuffer,
7         handles_provider::HandlesProvider,
8         CanceledBuffer, FormatBuilder,
9     },
10     memory::BufferHandles,
11     Rect,
12 };
13 
14 pub mod format;
15 pub mod stateful;
16 
17 pub enum CompletedInputBuffer<OP: BufferHandles> {
18     Dequeued(DqBuffer<Output, OP>),
19     Canceled(CanceledBuffer<OP>),
20 }
21 
22 pub trait InputDoneCallback<OP: BufferHandles>: Fn(CompletedInputBuffer<OP>) {}
23 impl<OP, F> InputDoneCallback<OP> for F
24 where
25     OP: BufferHandles,
26     F: Fn(CompletedInputBuffer<OP>),
27 {
28 }
29 
30 // TODO: add errors?
31 pub enum DecoderEvent<P: HandlesProvider> {
32     /// Emitted when a frame is decoded.
33     ///
34     /// The parameter is the dequeued buffer, containing the plane handles of
35     /// the decoded frame as well as its V4L2 parameters such as flags. The
36     /// flags remain untouched, but the client should not take action on some
37     /// of them: for instance, when the `V4L2_BUF_FLAG_LAST` is set, the proper
38     /// corresponding event (resolution change or end of stream) will be
39     /// signaled appropriately.
40     FrameDecoded(DqBuffer<Capture, P::HandleType>),
41     /// Emitted when a previously requested `drain` request completes.
42     ///
43     /// When this event is emitted, the client knows that all the frames
44     /// corresponding to all the input buffers queued before the `drain` request
45     /// have been emitted.
46     EndOfStream,
47 }
48 
49 pub trait DecoderEventCallback<P: HandlesProvider>:
50     FnMut(DecoderEvent<P>) + Send + 'static
51 {
52 }
53 impl<P, F> DecoderEventCallback<P> for F
54 where
55     P: HandlesProvider,
56     F: FnMut(DecoderEvent<P>) + Send + 'static,
57 {
58 }
59 
60 pub struct FormatChangedReply<P: HandlesProvider> {
61     pub provider: P,
62     pub mem_type: <P::HandleType as BufferHandles>::SupportedMemoryType,
63     pub num_buffers: usize,
64 }
65 
66 pub trait FormatChangedCallback<P: HandlesProvider>:
67     Fn(FormatBuilder, Rect, usize) -> anyhow::Result<FormatChangedReply<P>> + Send + 'static
68 {
69 }
70 impl<P, F> FormatChangedCallback<P> for F
71 where
72     P: HandlesProvider,
73     F: Fn(FormatBuilder, Rect, usize) -> anyhow::Result<FormatChangedReply<P>> + Send + 'static,
74 {
75 }
76