mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-26 13:31:00 +00:00
ndi: Fix/silence various clippy warnings
This commit is contained in:
parent
7a90500fe7
commit
718734ab18
5 changed files with 99 additions and 60 deletions
|
@ -1,6 +1,7 @@
|
|||
use crate::ndisys;
|
||||
use crate::ndisys::*;
|
||||
use std::ffi;
|
||||
use std::fmt;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
|
@ -226,11 +227,11 @@ impl<'a> RecvBuilder<'a> {
|
|||
p_ndi_name: ndi_name
|
||||
.as_ref()
|
||||
.map(|s| s.as_ptr())
|
||||
.unwrap_or_else(|| ptr::null_mut()),
|
||||
.unwrap_or(ptr::null_mut()),
|
||||
p_url_address: url_address
|
||||
.as_ref()
|
||||
.map(|s| s.as_ptr())
|
||||
.unwrap_or_else(|| ptr::null_mut()),
|
||||
.unwrap_or(ptr::null_mut()),
|
||||
},
|
||||
allow_video_fields: self.allow_video_fields,
|
||||
bandwidth: self.bandwidth,
|
||||
|
@ -252,6 +253,17 @@ pub struct RecvInstance(ptr::NonNull<::std::os::raw::c_void>);
|
|||
|
||||
unsafe impl Send for RecvInstance {}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct ReceiveError;
|
||||
|
||||
impl fmt::Display for ReceiveError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Receive error")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ReceiveError {}
|
||||
|
||||
impl RecvInstance {
|
||||
pub fn builder<'a>(
|
||||
ndi_name: Option<&'a str>,
|
||||
|
@ -284,7 +296,7 @@ impl RecvInstance {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn capture(&self, timeout_in_ms: u32) -> Result<Option<Frame>, ()> {
|
||||
pub fn capture(&self, timeout_in_ms: u32) -> Result<Option<Frame>, ReceiveError> {
|
||||
unsafe {
|
||||
let ptr = self.0.as_ptr();
|
||||
|
||||
|
@ -310,7 +322,7 @@ impl RecvInstance {
|
|||
NDIlib_frame_type_e::NDIlib_frame_type_metadata => Ok(Some(Frame::Metadata(
|
||||
MetadataFrame::Borrowed(metadata_frame, self),
|
||||
))),
|
||||
NDIlib_frame_type_e::NDIlib_frame_type_error => Err(()),
|
||||
NDIlib_frame_type_e::NDIlib_frame_type_error => Err(ReceiveError),
|
||||
_ => Ok(None),
|
||||
}
|
||||
}
|
||||
|
@ -444,6 +456,17 @@ pub enum VideoFrame<'a> {
|
|||
),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TryFromVideoFrameError;
|
||||
|
||||
impl fmt::Display for TryFromVideoFrameError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Can't handle video frame")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TryFromVideoFrameError {}
|
||||
|
||||
impl<'a> VideoFrame<'a> {
|
||||
pub fn xres(&self) -> i32 {
|
||||
match self {
|
||||
|
@ -702,7 +725,7 @@ impl<'a> VideoFrame<'a> {
|
|||
pub fn try_from_video_frame(
|
||||
frame: &'a gst_video::VideoFrameRef<&'a gst::BufferRef>,
|
||||
timecode: i64,
|
||||
) -> Result<Self, ()> {
|
||||
) -> Result<Self, TryFromVideoFrameError> {
|
||||
// Planar formats must be in contiguous memory
|
||||
let format = match frame.format() {
|
||||
gst_video::VideoFormat::Uyvy => ndisys::NDIlib_FourCC_video_type_UYVY,
|
||||
|
@ -711,14 +734,14 @@ impl<'a> VideoFrame<'a> {
|
|||
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
if (frame.plane_data(2).unwrap().as_ptr() as usize)
|
||||
.checked_sub(frame.plane_data(1).unwrap().as_ptr() as usize)
|
||||
!= Some((frame.height() as usize + 1) / 2 * frame.plane_stride()[1] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
ndisys::NDIlib_FourCC_video_type_I420
|
||||
|
@ -728,7 +751,7 @@ impl<'a> VideoFrame<'a> {
|
|||
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
ndisys::NDIlib_FourCC_video_type_NV12
|
||||
|
@ -738,7 +761,7 @@ impl<'a> VideoFrame<'a> {
|
|||
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
ndisys::NDIlib_FourCC_video_type_NV12
|
||||
|
@ -748,14 +771,14 @@ impl<'a> VideoFrame<'a> {
|
|||
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
if (frame.plane_data(2).unwrap().as_ptr() as usize)
|
||||
.checked_sub(frame.plane_data(1).unwrap().as_ptr() as usize)
|
||||
!= Some((frame.height() as usize + 1) / 2 * frame.plane_stride()[1] as usize)
|
||||
{
|
||||
return Err(());
|
||||
return Err(TryFromVideoFrameError);
|
||||
}
|
||||
|
||||
ndisys::NDIlib_FourCC_video_type_YV12
|
||||
|
@ -764,7 +787,7 @@ impl<'a> VideoFrame<'a> {
|
|||
gst_video::VideoFormat::Bgrx => ndisys::NDIlib_FourCC_video_type_BGRX,
|
||||
gst_video::VideoFormat::Rgba => ndisys::NDIlib_FourCC_video_type_RGBA,
|
||||
gst_video::VideoFormat::Rgbx => ndisys::NDIlib_FourCC_video_type_RGBX,
|
||||
_ => return Err(()),
|
||||
_ => return Err(TryFromVideoFrameError),
|
||||
};
|
||||
|
||||
let frame_format_type = match frame.info().interlace_mode() {
|
||||
|
@ -787,7 +810,7 @@ impl<'a> VideoFrame<'a> {
|
|||
{
|
||||
NDIlib_frame_format_type_e::NDIlib_frame_format_type_field_1
|
||||
}
|
||||
_ => return Err(()),
|
||||
_ => return Err(TryFromVideoFrameError),
|
||||
};
|
||||
|
||||
let picture_aspect_ratio =
|
||||
|
@ -835,6 +858,17 @@ pub enum AudioFrame<'a> {
|
|||
BorrowedRecv(NDIlib_audio_frame_v3_t, &'a RecvInstance),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TryFromAudioBufferError;
|
||||
|
||||
impl fmt::Display for TryFromAudioBufferError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Can't handle audio buffer")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for TryFromAudioBufferError {}
|
||||
|
||||
impl<'a> AudioFrame<'a> {
|
||||
pub fn sample_rate(&self) -> i32 {
|
||||
match self {
|
||||
|
@ -1012,13 +1046,15 @@ impl<'a> AudioFrame<'a> {
|
|||
info: &gst_audio::AudioInfo,
|
||||
buffer: &gst::BufferRef,
|
||||
timecode: i64,
|
||||
) -> Result<Self, ()> {
|
||||
) -> Result<Self, TryFromAudioBufferError> {
|
||||
if info.format() != gst_audio::AUDIO_FORMAT_F32 {
|
||||
return Err(());
|
||||
return Err(TryFromAudioBufferError);
|
||||
}
|
||||
|
||||
let map = buffer.map_readable().map_err(|_| ())?;
|
||||
let src_data = map.as_slice_of::<f32>().map_err(|_| ())?;
|
||||
let map = buffer.map_readable().map_err(|_| TryFromAudioBufferError)?;
|
||||
let src_data = map
|
||||
.as_slice_of::<f32>()
|
||||
.map_err(|_| TryFromAudioBufferError)?;
|
||||
|
||||
let no_samples = src_data.len() as i32 / info.channels() as i32;
|
||||
let channel_stride_or_data_size_in_bytes = no_samples * mem::size_of::<f32>() as i32;
|
||||
|
|
|
@ -348,9 +348,9 @@ impl AggregatorImpl for NdiSinkCombiner {
|
|||
None => None,
|
||||
};
|
||||
|
||||
let audio_buffer_segment_and_pad;
|
||||
let audio_buffer_segment_and_pad =
|
||||
if let Some(audio_pad) = self.audio_pad.lock().unwrap().clone() {
|
||||
audio_buffer_segment_and_pad = match audio_pad.peek_buffer() {
|
||||
match audio_pad.peek_buffer() {
|
||||
Some(audio_buffer) if audio_buffer.size() == 0 => {
|
||||
// Skip empty/gap audio buffer
|
||||
audio_pad.drop_buffer();
|
||||
|
@ -379,10 +379,10 @@ impl AggregatorImpl for NdiSinkCombiner {
|
|||
return Err(gst_base::AGGREGATOR_FLOW_NEED_DATA);
|
||||
}
|
||||
None => None,
|
||||
};
|
||||
} else {
|
||||
audio_buffer_segment_and_pad = None;
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut state_storage = self.state.lock().unwrap();
|
||||
let state = match &mut *state_storage {
|
||||
|
|
|
@ -124,6 +124,7 @@ impl ElementImpl for NdiSrcDemux {
|
|||
PAD_TEMPLATES.as_ref()
|
||||
}
|
||||
|
||||
#[allow(clippy::single_match)]
|
||||
fn change_state(
|
||||
&self,
|
||||
element: &Self::Type,
|
||||
|
@ -158,7 +159,10 @@ impl NdiSrcDemux {
|
|||
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
||||
gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
|
||||
|
||||
let meta = buffer.make_mut().meta_mut::<ndisrcmeta::NdiSrcMeta>().ok_or_else(|| {
|
||||
let meta = buffer
|
||||
.make_mut()
|
||||
.meta_mut::<ndisrcmeta::NdiSrcMeta>()
|
||||
.ok_or_else(|| {
|
||||
gst_error!(CAT, obj: element, "Buffer without NDI source meta");
|
||||
gst::FlowError::Error
|
||||
})?;
|
||||
|
@ -288,11 +292,7 @@ impl NdiSrcDemux {
|
|||
state.combiner.update_pad_flow(&srcpad, res)
|
||||
}
|
||||
|
||||
fn sink_event(&self,
|
||||
pad: &gst::Pad,
|
||||
element: &super::NdiSrcDemux,
|
||||
event: gst::Event
|
||||
) -> bool {
|
||||
fn sink_event(&self, pad: &gst::Pad, element: &super::NdiSrcDemux, event: gst::Event) -> bool {
|
||||
use gst::EventView;
|
||||
|
||||
gst_log!(CAT, obj: pad, "Handling event {:?}", event);
|
||||
|
@ -308,5 +308,4 @@ impl NdiSrcDemux {
|
|||
}
|
||||
pad.event_default(Some(element), event)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -136,7 +136,7 @@ pub const NDIlib_recv_color_format_ex_compressed_v5: NDIlib_recv_color_format_e
|
|||
pub const NDIlib_recv_color_format_ex_compressed_v5_with_audio: NDIlib_recv_color_format_e = 308;
|
||||
|
||||
const fn make_fourcc(fourcc: &[u8; 4]) -> u32 {
|
||||
((fourcc[0] as u32) << 0)
|
||||
(fourcc[0] as u32)
|
||||
| ((fourcc[1] as u32) << 8)
|
||||
| ((fourcc[2] as u32) << 16)
|
||||
| ((fourcc[3] as u32) << 24)
|
||||
|
|
|
@ -24,6 +24,7 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
|||
pub struct Receiver(Arc<ReceiverInner>);
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum AudioInfo {
|
||||
AudioInfo(gst_audio::AudioInfo),
|
||||
#[cfg(feature = "advanced-sdk")]
|
||||
|
@ -169,12 +170,14 @@ impl VideoInfo {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum Buffer {
|
||||
Audio(gst::Buffer, AudioInfo),
|
||||
Video(gst::Buffer, VideoInfo),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum ReceiverItem {
|
||||
Buffer(Buffer),
|
||||
Flushing,
|
||||
|
@ -564,6 +567,7 @@ impl Receiver {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn connect(
|
||||
element: &gst_base::BaseSrc,
|
||||
ndi_name: Option<&str>,
|
||||
|
|
Loading…
Reference in a new issue