1 // Copyright 2025 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 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::h265::H265; 11 use crate::decoder::stateless::vp8::Vp8; 12 use crate::decoder::stateless::vp9::Vp9; 13 use crate::decoder::stateless::DynStatelessVideoDecoder; 14 use crate::decoder::stateless::StatelessDecoder; 15 use crate::decoder::stateless::StatelessVideoDecoder; 16 use crate::decoder::BlockingMode; 17 use crate::video_frame::VideoFrame; 18 use crate::EncodedFormat; 19 use crate::Fourcc; 20 21 #[derive(Clone, Debug)] 22 pub struct C2V4L2DecoderOptions { 23 // TODO: This is currently unused, but we should plumb it to V4L2Device initialization. 24 pub video_device_path: Option<PathBuf>, 25 } 26 27 pub struct C2V4L2Decoder {} 28 29 impl C2DecoderBackend for C2V4L2Decoder { 30 type DecoderOptions = C2V4L2DecoderOptions; 31 new(_options: C2V4L2DecoderOptions) -> Result<Self, String>32 fn new(_options: C2V4L2DecoderOptions) -> Result<Self, String> { 33 Ok(Self {}) 34 } 35 36 // TODO: Actually query the driver for this information. supported_output_formats(&self) -> Result<Vec<Fourcc>, String>37 fn supported_output_formats(&self) -> Result<Vec<Fourcc>, String> { 38 Ok(vec![Fourcc::from(b"MM21")]) 39 } 40 get_decoder<V: VideoFrame + 'static>( &mut self, format: EncodedFormat, ) -> Result<DynStatelessVideoDecoder<V>, String>41 fn get_decoder<V: VideoFrame + 'static>( 42 &mut self, 43 format: EncodedFormat, 44 ) -> Result<DynStatelessVideoDecoder<V>, String> { 45 Ok(match format { 46 EncodedFormat::AV1 => StatelessDecoder::<Av1, _>::new_v4l2(BlockingMode::NonBlocking) 47 .map_err(|_| "Failed to instantiate AV1 decoder")? 48 .into_trait_object(), 49 EncodedFormat::H264 => StatelessDecoder::<H264, _>::new_v4l2(BlockingMode::NonBlocking) 50 .map_err(|_| "Failed to instantiate H264 decoder")? 51 .into_trait_object(), 52 EncodedFormat::H265 => StatelessDecoder::<H265, _>::new_v4l2(BlockingMode::NonBlocking) 53 .map_err(|_| "Failed to instantiate H265 decoder")? 54 .into_trait_object(), 55 EncodedFormat::VP8 => StatelessDecoder::<Vp8, _>::new_v4l2(BlockingMode::NonBlocking) 56 .map_err(|_| "Failed to instantiate VP8 decoder")? 57 .into_trait_object(), 58 EncodedFormat::VP9 => StatelessDecoder::<Vp9, _>::new_v4l2(BlockingMode::NonBlocking) 59 .map_err(|_| "Failed to instantiate VP9 decoder")? 60 .into_trait_object(), 61 }) 62 } 63 } 64