mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-01-11 19:55:25 +00:00
Refactor cargo clippy warnings
This commit is contained in:
parent
cf8b7db9bd
commit
8ce45f4f0d
4 changed files with 37 additions and 114 deletions
|
@ -72,7 +72,7 @@ lazy_static! {
|
||||||
|
|
||||||
static mut id_receiver: i8 = 0;
|
static mut id_receiver: i8 = 0;
|
||||||
|
|
||||||
fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: String, stream_name: String) -> i8 {
|
fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name: &str) -> i8 {
|
||||||
gst_debug!(cat, obj: element, "Starting NDI connection...");
|
gst_debug!(cat, obj: element, "Starting NDI connection...");
|
||||||
|
|
||||||
let mut receivers = hashmap_receivers.lock().unwrap();
|
let mut receivers = hashmap_receivers.lock().unwrap();
|
||||||
|
@ -177,7 +177,7 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: String, stream_na
|
||||||
.into_owned()
|
.into_owned()
|
||||||
);
|
);
|
||||||
|
|
||||||
let source = *p_sources.offset(no_source).clone();
|
let source = *p_sources.offset(no_source);
|
||||||
|
|
||||||
let source_ip = CStr::from_ptr(source.p_ip_address)
|
let source_ip = CStr::from_ptr(source.p_ip_address)
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
|
@ -233,8 +233,8 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: String, stream_na
|
||||||
ndi_receiver_info {
|
ndi_receiver_info {
|
||||||
stream_name: source_name.clone(),
|
stream_name: source_name.clone(),
|
||||||
ip: source_ip.clone(),
|
ip: source_ip.clone(),
|
||||||
video: video,
|
video,
|
||||||
audio: audio,
|
audio,
|
||||||
ndi_instance: NdiInstance { recv: pNDI_recv },
|
ndi_instance: NdiInstance { recv: pNDI_recv },
|
||||||
id: id_receiver,
|
id: id_receiver,
|
||||||
},
|
},
|
||||||
|
@ -247,7 +247,7 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: String, stream_na
|
||||||
// ndi_struct.start_pts = Some(since_the_epoch.as_secs() * 1000000000 +
|
// ndi_struct.start_pts = Some(since_the_epoch.as_secs() * 1000000000 +
|
||||||
// since_the_epoch.subsec_nanos() as u64);
|
// since_the_epoch.subsec_nanos() as u64);
|
||||||
gst_debug!(cat, obj: element, "Started NDI connection");
|
gst_debug!(cat, obj: element, "Started NDI connection");
|
||||||
return id_receiver;
|
id_receiver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +275,7 @@ fn stop_ndi(cat: gst::DebugCategory, element: &BaseSrc, id: i8) -> bool {
|
||||||
}
|
}
|
||||||
receivers.remove(&id);
|
receivers.remove(&id);
|
||||||
gst_debug!(cat, obj: element, "Closed NDI connection");
|
gst_debug!(cat, obj: element, "Closed NDI connection");
|
||||||
return true;
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer
|
// Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer
|
||||||
|
|
|
@ -293,14 +293,11 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||||
settings.id_receiver = connect_ndi(
|
settings.id_receiver = connect_ndi(
|
||||||
self.cat,
|
self.cat,
|
||||||
element,
|
element,
|
||||||
settings.ip.clone(),
|
&settings.ip.clone(),
|
||||||
settings.stream_name.clone(),
|
&settings.stream_name.clone(),
|
||||||
);
|
);
|
||||||
if settings.id_receiver == 0 {
|
|
||||||
return false;
|
settings.id_receiver != 0
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when shutting down the element so we can release all stream-related state
|
// Called when shutting down the element so we can release all stream-related state
|
||||||
|
@ -309,7 +306,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||||
*self.state.lock().unwrap() = Default::default();
|
*self.state.lock().unwrap() = Default::default();
|
||||||
|
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
stop_ndi(self.cat, element, settings.id_receiver.clone());
|
stop_ndi(self.cat, element, settings.id_receiver);
|
||||||
// Commented because when adding ndi destroy stopped in this line
|
// Commented because when adding ndi destroy stopped in this line
|
||||||
//*self.state.lock().unwrap() = Default::default();
|
//*self.state.lock().unwrap() = Default::default();
|
||||||
true
|
true
|
||||||
|
@ -317,41 +314,10 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||||
|
|
||||||
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
|
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
|
||||||
use gst::QueryView;
|
use gst::QueryView;
|
||||||
|
if let QueryView::Scheduling(ref mut q) = query.view_mut() {
|
||||||
match query.view_mut() {
|
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
|
||||||
// We only work in Push mode. In Pull mode, create() could be called with
|
q.add_scheduling_modes(&[gst::PadMode::Push]);
|
||||||
// arbitrary offsets and we would have to produce for that specific offset
|
return true;
|
||||||
QueryView::Scheduling(ref mut q) => {
|
|
||||||
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
|
|
||||||
q.add_scheduling_modes(&[gst::PadMode::Push]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// In Live mode we will have a latency equal to the number of samples in each buffer.
|
|
||||||
// We can't output samples before they were produced, and the last sample of a buffer
|
|
||||||
// is produced that much after the beginning, leading to this latency calculation
|
|
||||||
// QueryView::Latency(ref mut q) => {
|
|
||||||
// let settings = &*self.settings.lock().unwrap();
|
|
||||||
// let state = self.state.lock().unwrap();
|
|
||||||
//
|
|
||||||
// if let Some(ref _info) = state.info {
|
|
||||||
// // let latency = gst::SECOND
|
|
||||||
// // .mul_div_floor(1024 as u64, _info.rate() as u64)
|
|
||||||
// // .unwrap();
|
|
||||||
// let latency = gst::SECOND.mul_div_floor(3 as u64, 2 as u64).unwrap();
|
|
||||||
// // let latency = gst::SECOND
|
|
||||||
// // .mul_div_floor(1 as u64, 30 as u64)
|
|
||||||
// // .unwrap();
|
|
||||||
// // gst_debug!(self.cat, obj: element, "Returning latency {}", latency);
|
|
||||||
// let max = latency * 1843200;
|
|
||||||
// // println!("{:?}", latency);
|
|
||||||
// // println!("{:?}",max);
|
|
||||||
// q.set(true, latency, max);
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
BaseSrcBase::parent_query(element, query)
|
BaseSrcBase::parent_query(element, query)
|
||||||
}
|
}
|
||||||
|
@ -448,9 +414,9 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||||
let vec = Vec::from_raw_parts(audio_frame.p_data as *mut u8, buff_size, buff_size);
|
let vec = Vec::from_raw_parts(audio_frame.p_data as *mut u8, buff_size, buff_size);
|
||||||
let pts: gst::ClockTime = (pts * 100).into();
|
let pts: gst::ClockTime = (pts * 100).into();
|
||||||
|
|
||||||
let duration: gst::ClockTime = (((audio_frame.no_samples as f64
|
let duration: gst::ClockTime = (((f64::from(audio_frame.no_samples)
|
||||||
/ audio_frame.sample_rate as f64)
|
/ f64::from(audio_frame.sample_rate))
|
||||||
* 1000000000.0) as u64)
|
* 1_000_000_000.0) as u64)
|
||||||
.into();
|
.into();
|
||||||
let buffer = buffer.get_mut().unwrap();
|
let buffer = buffer.get_mut().unwrap();
|
||||||
|
|
||||||
|
@ -463,7 +429,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||||
buffer.set_duration(duration);
|
buffer.set_duration(duration);
|
||||||
buffer.set_offset(timestamp_data.offset);
|
buffer.set_offset(timestamp_data.offset);
|
||||||
buffer.set_offset_end(timestamp_data.offset + 1);
|
buffer.set_offset_end(timestamp_data.offset + 1);
|
||||||
timestamp_data.offset = timestamp_data.offset + 1;
|
timestamp_data.offset += timestamp_data.offset;
|
||||||
buffer.copy_from_slice(0, &vec).unwrap();
|
buffer.copy_from_slice(0, &vec).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,12 +104,12 @@ pub enum NDIlib_recv_color_format_e {
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub enum NDIlib_FourCC_type_e {
|
pub enum NDIlib_FourCC_type_e {
|
||||||
NDIlib_FourCC_type_UYVY = 1498831189,
|
NDIlib_FourCC_type_UYVY = 1_498_831_189,
|
||||||
NDIlib_FourCC_type_BGRA = 1095911234,
|
NDIlib_FourCC_type_BGRA = 1_095_911_234,
|
||||||
NDIlib_FourCC_type_BGRX = 1481787202,
|
NDIlib_FourCC_type_BGRX = 1_481_787_202,
|
||||||
NDIlib_FourCC_type_RGBA = 1094862674,
|
NDIlib_FourCC_type_RGBA = 1_094_862_674,
|
||||||
NDIlib_FourCC_type_RGBX = 1480738642,
|
NDIlib_FourCC_type_RGBX = 1_480_738_642,
|
||||||
NDIlib_FourCC_type_UYVA = 1096178005,
|
NDIlib_FourCC_type_UYVA = 1_096_178_005,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
|
|
|
@ -298,16 +298,11 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||||
settings.id_receiver = connect_ndi(
|
settings.id_receiver = connect_ndi(
|
||||||
self.cat,
|
self.cat,
|
||||||
element,
|
element,
|
||||||
settings.ip.clone(),
|
&settings.ip.clone(),
|
||||||
settings.stream_name.clone(),
|
&settings.stream_name.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if settings.id_receiver == 0 {
|
settings.id_receiver != 0
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when shutting down the element so we can release all stream-related state
|
// Called when shutting down the element so we can release all stream-related state
|
||||||
|
@ -316,7 +311,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||||
*self.state.lock().unwrap() = Default::default();
|
*self.state.lock().unwrap() = Default::default();
|
||||||
|
|
||||||
let settings = self.settings.lock().unwrap();
|
let settings = self.settings.lock().unwrap();
|
||||||
stop_ndi(self.cat, element, settings.id_receiver.clone());
|
stop_ndi(self.cat, element, settings.id_receiver);
|
||||||
// Commented because when adding ndi destroy stopped in this line
|
// Commented because when adding ndi destroy stopped in this line
|
||||||
//*self.state.lock().unwrap() = Default::default();
|
//*self.state.lock().unwrap() = Default::default();
|
||||||
true
|
true
|
||||||
|
@ -324,48 +319,10 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||||
|
|
||||||
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
|
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
|
||||||
use gst::QueryView;
|
use gst::QueryView;
|
||||||
match query.view_mut() {
|
if let QueryView::Scheduling(ref mut q) = query.view_mut() {
|
||||||
// We only work in Push mode. In Pull mode, create() could be called with
|
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
|
||||||
// arbitrary offsets and we would have to produce for that specific offset
|
q.add_scheduling_modes(&[gst::PadMode::Push]);
|
||||||
QueryView::Scheduling(ref mut q) => {
|
return true;
|
||||||
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
|
|
||||||
q.add_scheduling_modes(&[gst::PadMode::Push]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// In Live mode we will have a latency equal to the number of samples in each buffer.
|
|
||||||
// We can't output samples before they were produced, and the last sample of a buffer
|
|
||||||
// is produced that much after the beginning, leading to this latency calculation
|
|
||||||
// QueryView::Latency(ref mut q) => {
|
|
||||||
// let settings = self.settings.lock().unwrap();
|
|
||||||
// let state = self.state.lock().unwrap();
|
|
||||||
// println!("Dentro de query");
|
|
||||||
//
|
|
||||||
// if let Some(ref _info) = state.info {
|
|
||||||
// // let latency = gst::SECOND
|
|
||||||
// // .mul_div_floor(settings.samples_per_buffer as u64, info.rate() as u64)
|
|
||||||
// // .unwrap();
|
|
||||||
// let latency = gst::SECOND.mul_div_floor(3 as u64, 2 as u64).unwrap();
|
|
||||||
// let mut latency = gst::SECOND.mul_div_floor(settings.latency, 1000).unwrap();
|
|
||||||
// // if settings.latency > 2000{
|
|
||||||
// // println!("{:?}", element.get_name());
|
|
||||||
// // latency = gst::SECOND * 0;
|
|
||||||
// // }
|
|
||||||
// let latency = gst::SECOND * 0;
|
|
||||||
// // .mul_div_floor(1 as u64, 30 as u64)
|
|
||||||
// // .unwrap();
|
|
||||||
// // gst_debug!(self.cat, obj: element, "Returning latency {}", latency);
|
|
||||||
// let max = gst::SECOND * 120 * 1843200;
|
|
||||||
// // println!("{:?}", latency2);
|
|
||||||
// println!("{:?}", latency);
|
|
||||||
// println!("{:?}", (settings.latency / 1000));
|
|
||||||
// // println!("{:?}",max);
|
|
||||||
// q.set(true, latency, max);
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
BaseSrcBase::parent_query(element, query)
|
BaseSrcBase::parent_query(element, query)
|
||||||
}
|
}
|
||||||
|
@ -467,9 +424,9 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||||
let vec = Vec::from_raw_parts(video_frame.p_data as *mut u8, buff_size, buff_size);
|
let vec = Vec::from_raw_parts(video_frame.p_data as *mut u8, buff_size, buff_size);
|
||||||
let pts: gst::ClockTime = (pts * 100).into();
|
let pts: gst::ClockTime = (pts * 100).into();
|
||||||
|
|
||||||
let duration: gst::ClockTime = (((video_frame.frame_rate_D as f64
|
let duration: gst::ClockTime = (((f64::from(video_frame.frame_rate_D)
|
||||||
/ video_frame.frame_rate_N as f64)
|
/ f64::from(video_frame.frame_rate_N))
|
||||||
* 1000000000.0) as u64)
|
* 1_000_000_000.0) as u64)
|
||||||
.into();
|
.into();
|
||||||
let buffer = buffer.get_mut().unwrap();
|
let buffer = buffer.get_mut().unwrap();
|
||||||
|
|
||||||
|
@ -482,7 +439,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||||
buffer.set_duration(duration);
|
buffer.set_duration(duration);
|
||||||
buffer.set_offset(timestamp_data.offset);
|
buffer.set_offset(timestamp_data.offset);
|
||||||
buffer.set_offset_end(timestamp_data.offset + 1);
|
buffer.set_offset_end(timestamp_data.offset + 1);
|
||||||
timestamp_data.offset = timestamp_data.offset + 1;
|
timestamp_data.offset += timestamp_data.offset;
|
||||||
buffer.copy_from_slice(0, &vec).unwrap();
|
buffer.copy_from_slice(0, &vec).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue