From 1af2ce1a7b46201dbe0c30017d219e3d1e4d9219 Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Mon, 8 Jul 2024 15:18:23 +0900 Subject: [PATCH] decoder/stateless/v4l2/h264: remove unneeded `V4l2CtrlH264Sps` and `V4l2CtrlH264Pps` wrapper types We can achieve the same result through existing `From` implementations. --- src/decoder/stateless/h264/v4l2.rs | 18 +++++---- src/device/v4l2/stateless/controls/h264.rs | 44 ---------------------- 2 files changed, 10 insertions(+), 52 deletions(-) diff --git a/src/decoder/stateless/h264/v4l2.rs b/src/decoder/stateless/h264/v4l2.rs index fad5418e..7321b63d 100644 --- a/src/decoder/stateless/h264/v4l2.rs +++ b/src/decoder/stateless/h264/v4l2.rs @@ -5,6 +5,12 @@ use std::cell::RefCell; use std::rc::Rc; +use v4l2r::bindings::v4l2_ctrl_h264_pps; +use v4l2r::bindings::v4l2_ctrl_h264_sps; +use v4l2r::controls::codec::H264Pps; +use v4l2r::controls::codec::H264Sps; +use v4l2r::controls::SafeExtControl; + use crate::backend::v4l2::decoder::stateless::BackendHandle; use crate::backend::v4l2::decoder::stateless::V4l2Picture; use crate::backend::v4l2::decoder::stateless::V4l2StatelessDecoderBackend; @@ -25,9 +31,7 @@ use crate::decoder::BlockingMode; use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264DecodeMode; use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264DecodeParams; use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264DpbEntry; -use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264Pps; //TODO use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264ScalingMatrix; -use crate::device::v4l2::stateless::controls::h264::V4l2CtrlH264Sps; use crate::Resolution; impl StatelessDecoderBackendPicture for V4l2StatelessDecoderBackend { @@ -87,12 +91,10 @@ impl StatelessH264DecoderBackend for V4l2StatelessDecoderBackend { }); ref_pictures.push(ref_picture); } - let mut h264_sps = V4l2CtrlH264Sps::new(); - let mut h264_pps = V4l2CtrlH264Pps::new(); //TODO let mut h264_scaling_matrix = V4l2CtrlH264ScalingMatrix::new(); let mut h264_decode_params = V4l2CtrlH264DecodeParams::new(); - h264_sps.set(sps); - h264_pps.set(pps); + let h264_sps = SafeExtControl::::from(v4l2_ctrl_h264_sps::from(sps)); + let h264_pps = SafeExtControl::::from(v4l2_ctrl_h264_pps::from(pps)); h264_decode_params .set_picture_data(picture_data) .set_dpb_entries(dpb_entries) @@ -100,8 +102,8 @@ impl StatelessH264DecoderBackend for V4l2StatelessDecoderBackend { let mut picture = picture.borrow_mut(); picture .request() - .ioctl(&h264_sps) - .ioctl(&h264_pps) + .ioctl(h264_sps) + .ioctl(h264_pps) //TODO.ioctl(&h264_scaling_matrix) .ioctl(&h264_decode_params) .ioctl(V4l2CtrlH264DecodeMode::FrameBased); diff --git a/src/device/v4l2/stateless/controls/h264.rs b/src/device/v4l2/stateless/controls/h264.rs index 0aca98c0..f29f7ab1 100644 --- a/src/device/v4l2/stateless/controls/h264.rs +++ b/src/device/v4l2/stateless/controls/h264.rs @@ -48,9 +48,7 @@ use v4l2r::bindings::V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS; use v4l2r::bindings::V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE; use v4l2r::controls::codec::H264DecodeMode; use v4l2r::controls::codec::H264DecodeParams; -use v4l2r::controls::codec::H264Pps; use v4l2r::controls::codec::H264ScalingMatrix; -use v4l2r::controls::codec::H264Sps; use v4l2r::controls::SafeExtControl; impl From<&Sps> for v4l2_ctrl_h264_sps { @@ -201,48 +199,6 @@ impl From<&V4l2CtrlH264DpbEntry> for v4l2_h264_dpb_entry { } } -#[derive(Default)] -pub struct V4l2CtrlH264Sps { - handle: v4l2_ctrl_h264_sps, -} - -impl V4l2CtrlH264Sps { - pub fn new() -> Self { - Default::default() - } - pub fn set(&mut self, sps: &Sps) -> &mut Self { - self.handle = v4l2_ctrl_h264_sps::from(sps); - self - } -} - -impl From<&V4l2CtrlH264Sps> for SafeExtControl { - fn from(sps: &V4l2CtrlH264Sps) -> Self { - SafeExtControl::::from(sps.handle) - } -} - -#[derive(Default)] -pub struct V4l2CtrlH264Pps { - handle: v4l2_ctrl_h264_pps, -} - -impl V4l2CtrlH264Pps { - pub fn new() -> Self { - Default::default() - } - pub fn set(&mut self, pps: &Pps) -> &mut Self { - self.handle = v4l2_ctrl_h264_pps::from(pps); - self - } -} - -impl From<&V4l2CtrlH264Pps> for SafeExtControl { - fn from(pps: &V4l2CtrlH264Pps) -> Self { - SafeExtControl::::from(pps.handle) - } -} - #[derive(Default)] pub struct V4l2CtrlH264ScalingMatrix { handle: v4l2_ctrl_h264_scaling_matrix,