From d6ba009742d3e3e164aca4fb38b71aeec1ff2906 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 26 Dec 2021 12:02:09 +0200 Subject: [PATCH] Fix various clippy warnings --- plugins/examples/webrtcsink-stats-server.rs | 2 +- plugins/src/signaller/imp.rs | 2 +- plugins/src/signaller/mod.rs | 4 +-- plugins/src/webrtcsink/imp.rs | 36 +++++++++------------ plugins/src/webrtcsink/mod.rs | 6 ++-- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/plugins/examples/webrtcsink-stats-server.rs b/plugins/examples/webrtcsink-stats-server.rs index 68304ad4..846b86e7 100644 --- a/plugins/examples/webrtcsink-stats-server.rs +++ b/plugins/examples/webrtcsink-stats-server.rs @@ -138,7 +138,7 @@ async fn run(args: Args) -> Result<(), Error> { task::spawn(async move { let mut interval = async_std::stream::interval(std::time::Duration::from_millis(100)); - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { if let Some(ws) = ws_clone.upgrade() { let stats = ws.property::("stats"); let stats = serialize_value(&stats.to_value()).unwrap(); diff --git a/plugins/src/signaller/imp.rs b/plugins/src/signaller/imp.rs index 9668a46c..6eafd3cd 100644 --- a/plugins/src/signaller/imp.rs +++ b/plugins/src/signaller/imp.rs @@ -219,7 +219,7 @@ impl Signaller { } pub fn start(&self, element: &WebRTCSink) { - let this = self.instance().clone(); + let this = self.instance(); let element_clone = element.clone(); task::spawn(async move { let this = Self::from_instance(&this); diff --git a/plugins/src/signaller/mod.rs b/plugins/src/signaller/mod.rs index 9cdbacd9..8caf2e6b 100644 --- a/plugins/src/signaller/mod.rs +++ b/plugins/src/signaller/mod.rs @@ -55,8 +55,8 @@ impl Signallable for Signaller { } } -impl Signaller { - pub fn new() -> Self { +impl Default for Signaller { + fn default() -> Self { glib::Object::new(&[]).unwrap() } } diff --git a/plugins/src/webrtcsink/imp.rs b/plugins/src/webrtcsink/imp.rs index 9669e443..c8074e65 100644 --- a/plugins/src/webrtcsink/imp.rs +++ b/plugins/src/webrtcsink/imp.rs @@ -84,8 +84,6 @@ struct WebRTCPad { pad: gst::Pad, /// The (fixed) caps of the corresponding input stream in_caps: gst::Caps, - /// Our offer caps - caps: gst::Caps, /// The m= line index in the SDP media_idx: u32, ssrc: u32, @@ -225,7 +223,7 @@ impl Default for Settings { impl Default for State { fn default() -> Self { - let signaller = Signaller::new(); + let signaller = Signaller::default(); Self { signaller: Box::new(signaller), @@ -461,7 +459,7 @@ impl VideoEncoder { let width = height.mul_div_ceil(ratio.numer(), ratio.denom()).unwrap(); - width + 1 >> 1 << 1 + (width + 1) & !1 } fn set_bitrate(&mut self, element: &super::WebRTCSink, bitrate: i32) { @@ -838,7 +836,7 @@ impl State { && element.current_state() == gst::State::Playing && self.codec_discovery_done { - if let Err(err) = self.signaller.start(&element) { + if let Err(err) = self.signaller.start(element) { gst_error!(CAT, obj: element, "error: {}", err); gst::element_error!( element, @@ -943,7 +941,6 @@ impl Consumer { WebRTCPad { pad, in_caps: stream.in_caps.as_ref().unwrap().clone(), - caps: payloader_caps, media_idx: media_idx as u32, ssrc, stream_name: stream.sink_pad.name().to_string(), @@ -1030,8 +1027,8 @@ impl Consumer { if codec.is_video { let video_info = gst_video::VideoInfo::from_caps(&webrtc_pad.in_caps)?; let mut enc = VideoEncoder::new( - enc.clone(), - raw_filter.clone(), + enc, + raw_filter, video_info, &self.peer_id, codec.caps.structure(0).unwrap().name(), @@ -1151,7 +1148,7 @@ impl WebRTCSink { /* Now iterate user-provided codec preferences and determine * whether we can fulfill these preferences */ let settings = self.settings.lock().unwrap(); - let mut payload = (96..128).into_iter(); + let mut payload = 96..128; settings .video_caps @@ -1566,7 +1563,7 @@ impl WebRTCSink { state .streams .iter() - .for_each(|(_, stream)| consumer.request_webrtcbin_pad(element, &settings, &stream)); + .for_each(|(_, stream)| consumer.request_webrtcbin_pad(element, &settings, stream)); let clock = element.clock(); @@ -1728,7 +1725,7 @@ impl WebRTCSink { let mut interval = async_std::stream::interval(std::time::Duration::from_millis(100)); - while let Some(_) = interval.next().await { + while interval.next().await.is_some() { let element_clone = element_clone.clone(); let peer_id_clone = peer_id_clone.clone(); if let Some(webrtcbin) = webrtcbin.upgrade() { @@ -1768,8 +1765,7 @@ impl WebRTCSink { ) -> Result<(), WebRTCSinkError> { let state = self.state.lock().unwrap(); - let sdp_mline_index = - sdp_mline_index.ok_or_else(|| WebRTCSinkError::MandatorySdpMlineIndex)?; + let sdp_mline_index = sdp_mline_index.ok_or(WebRTCSinkError::MandatorySdpMlineIndex)?; if let Some(consumer) = state.consumers.get(peer_id) { gst_trace!(CAT, "adding ice candidate for peer {}", peer_id); @@ -1945,7 +1941,7 @@ impl WebRTCSink { let futs = codecs .iter() .filter(|(_, codec)| codec.is_video == is_video) - .map(|(_, codec)| WebRTCSink::run_discovery_pipeline(element, &codec, &sink_caps)); + .map(|(_, codec)| WebRTCSink::run_discovery_pipeline(element, codec, &sink_caps)); for ret in futures::future::join_all(futs).await { match ret { @@ -2044,10 +2040,8 @@ impl WebRTCSink { .for_each(|(_, mut stream)| { if stream.sink_pad.upcast_ref::() == pad { stream.in_caps = Some(e.caps().to_owned()); - } else { - if stream.in_caps.is_none() { - all_pads_have_caps = false; - } + } else if stream.in_caps.is_none() { + all_pads_have_caps = false; } }); @@ -2206,14 +2200,14 @@ impl ObjectImpl for WebRTCSink { settings.video_caps = value .get::>() .expect("type checked upstream") - .unwrap_or_else(|| gst::Caps::new_empty()); + .unwrap_or_else(gst::Caps::new_empty); } "audio-caps" => { let mut settings = self.settings.lock().unwrap(); settings.audio_caps = value .get::>() .expect("type checked upstream") - .unwrap_or_else(|| gst::Caps::new_empty()); + .unwrap_or_else(gst::Caps::new_empty); } "stun-server" => { let mut settings = self.settings.lock().unwrap(); @@ -2422,7 +2416,7 @@ impl ElementImpl for WebRTCSink { name }; - let sink_pad = gst::GhostPad::builder_with_template(&templ, Some(name.as_str())) + let sink_pad = gst::GhostPad::builder_with_template(templ, Some(name.as_str())) .event_function(|pad, parent, event| { WebRTCSink::catch_panic_pad_function( parent, diff --git a/plugins/src/webrtcsink/mod.rs b/plugins/src/webrtcsink/mod.rs index 28165c94..e6948100 100644 --- a/plugins/src/webrtcsink/mod.rs +++ b/plugins/src/webrtcsink/mod.rs @@ -67,11 +67,13 @@ pub trait SignallableObject: AsRef + Signallable {} impl + Signallable> SignallableObject for T {} -impl WebRTCSink { - pub fn new() -> Self { +impl Default for WebRTCSink { + fn default() -> Self { glib::Object::new(&[]).unwrap() } +} +impl WebRTCSink { pub fn with_signaller(signaller: Box) -> Self { let ret: WebRTCSink = glib::Object::new(&[]).unwrap();