forge
Explore
Log in

Don't you dare go Hollow

edith

Clone
★ 0

0 watching0 forksRust18.3 MiB8c7bf80Tahinli3 months ago114 commits

c2_v4l2_decoder.rs60 lines, 2.3 KiBHistoryRawDownload
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
5use std::path::PathBuf;
6
7use crate::c2_wrapper::c2_decoder::C2DecoderBackend;
8use crate::decoder::stateless::av1::Av1;
9use crate::decoder::stateless::h264::H264;
10use crate::decoder::stateless::vp8::Vp8;
11use crate::decoder::stateless::vp9::Vp9;
12use crate::decoder::stateless::DynStatelessVideoDecoder;
13use crate::decoder::stateless::StatelessDecoder;
14use crate::decoder::stateless::StatelessVideoDecoder;
15use crate::decoder::BlockingMode;
16use crate::video_frame::VideoFrame;
17use crate::EncodedFormat;
18use crate::Fourcc;
19
20#[derive(Clone, Debug)]
21pub struct C2V4L2DecoderOptions {
22 // TODO: This is currently unused, but we should plumb it to V4L2Device initialization.
23 pub video_device_path: Option<PathBuf>,
24}
25
26pub struct C2V4L2Decoder {}
27
28impl C2DecoderBackend for C2V4L2Decoder {
29 type DecoderOptions = C2V4L2DecoderOptions;
30
31 fn new(_options: C2V4L2DecoderOptions) -> Result<Self, String> {
32 Ok(Self {})
33 }
34
35 // TODO: Actually query the driver for this information.
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}