mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2024-11-29 23:11:01 +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 crate::ndisys::*;
|
use crate::ndisys::*;
|
||||||
use std::ffi;
|
use std::ffi;
|
||||||
|
use std::fmt;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
|
@ -226,11 +227,11 @@ impl<'a> RecvBuilder<'a> {
|
||||||
p_ndi_name: ndi_name
|
p_ndi_name: ndi_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.as_ptr())
|
.map(|s| s.as_ptr())
|
||||||
.unwrap_or_else(|| ptr::null_mut()),
|
.unwrap_or(ptr::null_mut()),
|
||||||
p_url_address: url_address
|
p_url_address: url_address
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|s| s.as_ptr())
|
.map(|s| s.as_ptr())
|
||||||
.unwrap_or_else(|| ptr::null_mut()),
|
.unwrap_or(ptr::null_mut()),
|
||||||
},
|
},
|
||||||
allow_video_fields: self.allow_video_fields,
|
allow_video_fields: self.allow_video_fields,
|
||||||
bandwidth: self.bandwidth,
|
bandwidth: self.bandwidth,
|
||||||
|
@ -252,6 +253,17 @@ pub struct RecvInstance(ptr::NonNull<::std::os::raw::c_void>);
|
||||||
|
|
||||||
unsafe impl Send for RecvInstance {}
|
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 {
|
impl RecvInstance {
|
||||||
pub fn builder<'a>(
|
pub fn builder<'a>(
|
||||||
ndi_name: Option<&'a str>,
|
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 {
|
unsafe {
|
||||||
let ptr = self.0.as_ptr();
|
let ptr = self.0.as_ptr();
|
||||||
|
|
||||||
|
@ -310,7 +322,7 @@ impl RecvInstance {
|
||||||
NDIlib_frame_type_e::NDIlib_frame_type_metadata => Ok(Some(Frame::Metadata(
|
NDIlib_frame_type_e::NDIlib_frame_type_metadata => Ok(Some(Frame::Metadata(
|
||||||
MetadataFrame::Borrowed(metadata_frame, self),
|
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),
|
_ => 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> {
|
impl<'a> VideoFrame<'a> {
|
||||||
pub fn xres(&self) -> i32 {
|
pub fn xres(&self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
|
@ -702,7 +725,7 @@ impl<'a> VideoFrame<'a> {
|
||||||
pub fn try_from_video_frame(
|
pub fn try_from_video_frame(
|
||||||
frame: &'a gst_video::VideoFrameRef<&'a gst::BufferRef>,
|
frame: &'a gst_video::VideoFrameRef<&'a gst::BufferRef>,
|
||||||
timecode: i64,
|
timecode: i64,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, TryFromVideoFrameError> {
|
||||||
// Planar formats must be in contiguous memory
|
// Planar formats must be in contiguous memory
|
||||||
let format = match frame.format() {
|
let format = match frame.format() {
|
||||||
gst_video::VideoFormat::Uyvy => ndisys::NDIlib_FourCC_video_type_UYVY,
|
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)
|
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||||
!= Some(frame.height() as usize * frame.plane_stride()[0] 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)
|
if (frame.plane_data(2).unwrap().as_ptr() as usize)
|
||||||
.checked_sub(frame.plane_data(1).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)
|
!= Some((frame.height() as usize + 1) / 2 * frame.plane_stride()[1] as usize)
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(TryFromVideoFrameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndisys::NDIlib_FourCC_video_type_I420
|
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)
|
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(TryFromVideoFrameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndisys::NDIlib_FourCC_video_type_NV12
|
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)
|
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||||
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
!= Some(frame.height() as usize * frame.plane_stride()[0] as usize)
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(TryFromVideoFrameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndisys::NDIlib_FourCC_video_type_NV12
|
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)
|
.checked_sub(frame.plane_data(0).unwrap().as_ptr() as usize)
|
||||||
!= Some(frame.height() as usize * frame.plane_stride()[0] 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)
|
if (frame.plane_data(2).unwrap().as_ptr() as usize)
|
||||||
.checked_sub(frame.plane_data(1).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)
|
!= Some((frame.height() as usize + 1) / 2 * frame.plane_stride()[1] as usize)
|
||||||
{
|
{
|
||||||
return Err(());
|
return Err(TryFromVideoFrameError);
|
||||||
}
|
}
|
||||||
|
|
||||||
ndisys::NDIlib_FourCC_video_type_YV12
|
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::Bgrx => ndisys::NDIlib_FourCC_video_type_BGRX,
|
||||||
gst_video::VideoFormat::Rgba => ndisys::NDIlib_FourCC_video_type_RGBA,
|
gst_video::VideoFormat::Rgba => ndisys::NDIlib_FourCC_video_type_RGBA,
|
||||||
gst_video::VideoFormat::Rgbx => ndisys::NDIlib_FourCC_video_type_RGBX,
|
gst_video::VideoFormat::Rgbx => ndisys::NDIlib_FourCC_video_type_RGBX,
|
||||||
_ => return Err(()),
|
_ => return Err(TryFromVideoFrameError),
|
||||||
};
|
};
|
||||||
|
|
||||||
let frame_format_type = match frame.info().interlace_mode() {
|
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
|
NDIlib_frame_format_type_e::NDIlib_frame_format_type_field_1
|
||||||
}
|
}
|
||||||
_ => return Err(()),
|
_ => return Err(TryFromVideoFrameError),
|
||||||
};
|
};
|
||||||
|
|
||||||
let picture_aspect_ratio =
|
let picture_aspect_ratio =
|
||||||
|
@ -835,6 +858,17 @@ pub enum AudioFrame<'a> {
|
||||||
BorrowedRecv(NDIlib_audio_frame_v3_t, &'a RecvInstance),
|
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> {
|
impl<'a> AudioFrame<'a> {
|
||||||
pub fn sample_rate(&self) -> i32 {
|
pub fn sample_rate(&self) -> i32 {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1012,13 +1046,15 @@ impl<'a> AudioFrame<'a> {
|
||||||
info: &gst_audio::AudioInfo,
|
info: &gst_audio::AudioInfo,
|
||||||
buffer: &gst::BufferRef,
|
buffer: &gst::BufferRef,
|
||||||
timecode: i64,
|
timecode: i64,
|
||||||
) -> Result<Self, ()> {
|
) -> Result<Self, TryFromAudioBufferError> {
|
||||||
if info.format() != gst_audio::AUDIO_FORMAT_F32 {
|
if info.format() != gst_audio::AUDIO_FORMAT_F32 {
|
||||||
return Err(());
|
return Err(TryFromAudioBufferError);
|
||||||
}
|
}
|
||||||
|
|
||||||
let map = buffer.map_readable().map_err(|_| ())?;
|
let map = buffer.map_readable().map_err(|_| TryFromAudioBufferError)?;
|
||||||
let src_data = map.as_slice_of::<f32>().map_err(|_| ())?;
|
let src_data = map
|
||||||
|
.as_slice_of::<f32>()
|
||||||
|
.map_err(|_| TryFromAudioBufferError)?;
|
||||||
|
|
||||||
let no_samples = src_data.len() as i32 / info.channels() as i32;
|
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;
|
let channel_stride_or_data_size_in_bytes = no_samples * mem::size_of::<f32>() as i32;
|
||||||
|
|
|
@ -348,41 +348,41 @@ impl AggregatorImpl for NdiSinkCombiner {
|
||||||
None => None,
|
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() {
|
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 => {
|
Some(audio_buffer) if audio_buffer.size() == 0 => {
|
||||||
// Skip empty/gap audio buffer
|
// Skip empty/gap audio buffer
|
||||||
audio_pad.drop_buffer();
|
audio_pad.drop_buffer();
|
||||||
gst_trace!(CAT, obj: agg, "Empty audio buffer, waiting for next");
|
gst_trace!(CAT, obj: agg, "Empty audio buffer, waiting for next");
|
||||||
return Err(gst_base::AGGREGATOR_FLOW_NEED_DATA);
|
return Err(gst_base::AGGREGATOR_FLOW_NEED_DATA);
|
||||||
}
|
}
|
||||||
Some(audio_buffer) => {
|
Some(audio_buffer) => {
|
||||||
let audio_segment = audio_pad.segment();
|
let audio_segment = audio_pad.segment();
|
||||||
let audio_segment = match audio_segment.downcast::<gst::ClockTime>() {
|
let audio_segment = match audio_segment.downcast::<gst::ClockTime>() {
|
||||||
Ok(audio_segment) => audio_segment,
|
Ok(audio_segment) => audio_segment,
|
||||||
Err(audio_segment) => {
|
Err(audio_segment) => {
|
||||||
gst_error!(
|
gst_error!(
|
||||||
CAT,
|
CAT,
|
||||||
obj: agg,
|
obj: agg,
|
||||||
"Audio segment of wrong format {:?}",
|
"Audio segment of wrong format {:?}",
|
||||||
audio_segment.format()
|
audio_segment.format()
|
||||||
);
|
);
|
||||||
return Err(gst::FlowError::Error);
|
return Err(gst::FlowError::Error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((audio_buffer, audio_segment, audio_pad))
|
Some((audio_buffer, audio_segment, audio_pad))
|
||||||
|
}
|
||||||
|
None if !audio_pad.is_eos() => {
|
||||||
|
gst_trace!(CAT, obj: agg, "Waiting for audio buffer");
|
||||||
|
return Err(gst_base::AGGREGATOR_FLOW_NEED_DATA);
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
}
|
}
|
||||||
None if !audio_pad.is_eos() => {
|
} else {
|
||||||
gst_trace!(CAT, obj: agg, "Waiting for audio buffer");
|
None
|
||||||
return Err(gst_base::AGGREGATOR_FLOW_NEED_DATA);
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
audio_buffer_segment_and_pad = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut state_storage = self.state.lock().unwrap();
|
let mut state_storage = self.state.lock().unwrap();
|
||||||
let state = match &mut *state_storage {
|
let state = match &mut *state_storage {
|
||||||
|
|
|
@ -124,6 +124,7 @@ impl ElementImpl for NdiSrcDemux {
|
||||||
PAD_TEMPLATES.as_ref()
|
PAD_TEMPLATES.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::single_match)]
|
||||||
fn change_state(
|
fn change_state(
|
||||||
&self,
|
&self,
|
||||||
element: &Self::Type,
|
element: &Self::Type,
|
||||||
|
@ -158,10 +159,13 @@ impl NdiSrcDemux {
|
||||||
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
) -> Result<gst::FlowSuccess, gst::FlowError> {
|
||||||
gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
|
gst_log!(CAT, obj: pad, "Handling buffer {:?}", buffer);
|
||||||
|
|
||||||
let meta = buffer.make_mut().meta_mut::<ndisrcmeta::NdiSrcMeta>().ok_or_else(|| {
|
let meta = buffer
|
||||||
gst_error!(CAT, obj: element, "Buffer without NDI source meta");
|
.make_mut()
|
||||||
gst::FlowError::Error
|
.meta_mut::<ndisrcmeta::NdiSrcMeta>()
|
||||||
})?;
|
.ok_or_else(|| {
|
||||||
|
gst_error!(CAT, obj: element, "Buffer without NDI source meta");
|
||||||
|
gst::FlowError::Error
|
||||||
|
})?;
|
||||||
|
|
||||||
let mut events = vec![];
|
let mut events = vec![];
|
||||||
let srcpad;
|
let srcpad;
|
||||||
|
@ -288,11 +292,7 @@ impl NdiSrcDemux {
|
||||||
state.combiner.update_pad_flow(&srcpad, res)
|
state.combiner.update_pad_flow(&srcpad, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sink_event(&self,
|
fn sink_event(&self, pad: &gst::Pad, element: &super::NdiSrcDemux, event: gst::Event) -> bool {
|
||||||
pad: &gst::Pad,
|
|
||||||
element: &super::NdiSrcDemux,
|
|
||||||
event: gst::Event
|
|
||||||
) -> bool {
|
|
||||||
use gst::EventView;
|
use gst::EventView;
|
||||||
|
|
||||||
gst_log!(CAT, obj: pad, "Handling event {:?}", event);
|
gst_log!(CAT, obj: pad, "Handling event {:?}", event);
|
||||||
|
@ -308,5 +308,4 @@ impl NdiSrcDemux {
|
||||||
}
|
}
|
||||||
pad.event_default(Some(element), event)
|
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;
|
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 {
|
const fn make_fourcc(fourcc: &[u8; 4]) -> u32 {
|
||||||
((fourcc[0] as u32) << 0)
|
(fourcc[0] as u32)
|
||||||
| ((fourcc[1] as u32) << 8)
|
| ((fourcc[1] as u32) << 8)
|
||||||
| ((fourcc[2] as u32) << 16)
|
| ((fourcc[2] as u32) << 16)
|
||||||
| ((fourcc[3] as u32) << 24)
|
| ((fourcc[3] as u32) << 24)
|
||||||
|
|
|
@ -24,6 +24,7 @@ static CAT: Lazy<gst::DebugCategory> = Lazy::new(|| {
|
||||||
pub struct Receiver(Arc<ReceiverInner>);
|
pub struct Receiver(Arc<ReceiverInner>);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum AudioInfo {
|
pub enum AudioInfo {
|
||||||
AudioInfo(gst_audio::AudioInfo),
|
AudioInfo(gst_audio::AudioInfo),
|
||||||
#[cfg(feature = "advanced-sdk")]
|
#[cfg(feature = "advanced-sdk")]
|
||||||
|
@ -169,12 +170,14 @@ impl VideoInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum Buffer {
|
pub enum Buffer {
|
||||||
Audio(gst::Buffer, AudioInfo),
|
Audio(gst::Buffer, AudioInfo),
|
||||||
Video(gst::Buffer, VideoInfo),
|
Video(gst::Buffer, VideoInfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum ReceiverItem {
|
pub enum ReceiverItem {
|
||||||
Buffer(Buffer),
|
Buffer(Buffer),
|
||||||
Flushing,
|
Flushing,
|
||||||
|
@ -564,6 +567,7 @@ impl Receiver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn connect(
|
pub fn connect(
|
||||||
element: &gst_base::BaseSrc,
|
element: &gst_base::BaseSrc,
|
||||||
ndi_name: Option<&str>,
|
ndi_name: Option<&str>,
|
||||||
|
|
Loading…
Reference in a new issue