| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | use std::path::PathBuf; |
| 6 | |
| 7 | use crate::c2_wrapper::c2_decoder::C2DecoderBackend; |
| 8 | use crate::decoder::stateless::av1::Av1; |
| 9 | use crate::decoder::stateless::h264::H264; |
| 10 | use crate::decoder::stateless::vp8::Vp8; |
| 11 | use crate::decoder::stateless::vp9::Vp9; |
| 12 | use crate::decoder::stateless::DynStatelessVideoDecoder; |
| 13 | use crate::decoder::stateless::StatelessDecoder; |
| 14 | use crate::decoder::stateless::StatelessVideoDecoder; |
| 15 | use crate::decoder::BlockingMode; |
| 16 | use crate::video_frame::VideoFrame; |
| 17 | use crate::EncodedFormat; |
| 18 | use crate::Fourcc; |
| 19 | |
| 20 | #[derive(Clone, Debug)] |
| 21 | pub struct C2V4L2DecoderOptions { |
| 22 | |
| 23 | pub video_device_path: Option<PathBuf>, |
| 24 | } |
| 25 | |
| 26 | pub struct C2V4L2Decoder {} |
| 27 | |
| 28 | impl C2DecoderBackend for C2V4L2Decoder { |
| 29 | type DecoderOptions = C2V4L2DecoderOptions; |
| 30 | |
| 31 | fn new(_options: C2V4L2DecoderOptions) -> Result<Self, String> { |
| 32 | Ok(Self {}) |
| 33 | } |
| 34 | |
| 35 | |
| 36 | fn supported_output_formats(&self) -> Vec<Fourcc> { |
| 37 | vec![Fourcc::from(b"MM21")] |
| 38 | } |
| 39 | |
| 40 | fn get_decoder<V: VideoFrame + 'static>( |
| 41 | &mut self, |
| 42 | format: EncodedFormat, |
| 43 | ) -> Result<DynStatelessVideoDecoder<V>, String> { |
| 44 | Ok(match format { |
| 45 | EncodedFormat::AV1 => StatelessDecoder::<Av1, _>::new_v4l2(BlockingMode::NonBlocking) |
| 46 | .map_err(|_| "Failed to instantiate AV1 decoder")? |
| 47 | .into_trait_object(), |
| 48 | EncodedFormat::H264 => StatelessDecoder::<H264, _>::new_v4l2(BlockingMode::NonBlocking) |
| 49 | .map_err(|_| "Failed to instantiate H264 decoder")? |
| 50 | .into_trait_object(), |
| 51 | EncodedFormat::VP8 => StatelessDecoder::<Vp8, _>::new_v4l2(BlockingMode::NonBlocking) |
| 52 | .map_err(|_| "Failed to instantiate VP8 decoder")? |
| 53 | .into_trait_object(), |
| 54 | EncodedFormat::VP9 => StatelessDecoder::<Vp9, _>::new_v4l2(BlockingMode::NonBlocking) |
| 55 | .map_err(|_| "Failed to instantiate VP9 decoder")? |
| 56 | .into_trait_object(), |
| 57 | _ => return Err(format!("Unsupported format {format:?}")), |
| 58 | }) |
| 59 | } |
| 60 | } |