diff --git a/gst-plugin-audiofx/src/audioecho.rs b/gst-plugin-audiofx/src/audioecho.rs index 0fec1538..5fdb9bd2 100644 --- a/gst-plugin-audiofx/src/audioecho.rs +++ b/gst-plugin-audiofx/src/audioecho.rs @@ -296,7 +296,7 @@ impl BaseTransformImpl for AudioEcho { } let info = gst_audio::AudioInfo::from_caps(incaps) - .or(Err(gst_loggable_error!(CAT, "Failed to parse input caps")))?; + .or_else(|_| Err(gst_loggable_error!(CAT, "Failed to parse input caps")))?; let max_delay = self.settings.lock().unwrap().max_delay; let size = max_delay * (info.rate() as u64) / gst::SECOND_VAL; let buffer_size = size * (info.channels() as u64); diff --git a/gst-plugin-cdg/tests/cdgdec.rs b/gst-plugin-cdg/tests/cdgdec.rs index c9a6b134..69b9d3ff 100644 --- a/gst-plugin-cdg/tests/cdgdec.rs +++ b/gst-plugin-cdg/tests/cdgdec.rs @@ -94,8 +94,7 @@ fn test_cdgdec() { err.get_error() ); eprintln!("Debugging information: {:?}", err.get_debug()); - assert!(true); - break; + unreachable!(); } MessageView::Eos(..) => break, _ => (), diff --git a/gst-plugin-closedcaption/tests/mcc_parse.rs b/gst-plugin-closedcaption/tests/mcc_parse.rs index 82b47aaf..42b0f3c9 100644 --- a/gst-plugin-closedcaption/tests/mcc_parse.rs +++ b/gst-plugin-closedcaption/tests/mcc_parse.rs @@ -85,7 +85,9 @@ fn test_parse() { } else { expected_timecode = Some(tc_meta.get_tc()); } - expected_timecode.as_mut().map(|tc| tc.increment_frame()); + if let Some(ref mut tc) = expected_timecode { + tc.increment_frame(); + } } data = &data[l..]; } @@ -108,13 +110,15 @@ fn test_parse() { } else { expected_timecode = Some(tc_meta.get_tc()); } - expected_timecode.as_mut().map(|tc| tc.increment_frame()); + if let Some(ref mut tc) = expected_timecode { + tc.increment_frame(); + } } assert!(expected_timecode.is_some()); - assert_eq!(input_len, 28818); - assert_eq!(output_len, 42383); - assert_eq!(checksum, 3988480); + assert_eq!(input_len, 28_818); + assert_eq!(output_len, 42_383); + assert_eq!(checksum, 3_988_480); let caps = h .get_sinkpad() @@ -174,9 +178,9 @@ fn test_pull() { 1.0, gst::SeekFlags::FLUSH, gst::SeekType::Set, - gst::GenericFormattedValue::Time(gst::SECOND.into()), + gst::GenericFormattedValue::Time(gst::SECOND), gst::SeekType::Set, - gst::GenericFormattedValue::Time((2 * gst::SECOND).into()), + gst::GenericFormattedValue::Time(2 * gst::SECOND), ) .build(), ); diff --git a/gst-plugin-closedcaption/tests/scc_enc.rs b/gst-plugin-closedcaption/tests/scc_enc.rs index 0ffc685f..92003df9 100644 --- a/gst-plugin-closedcaption/tests/scc_enc.rs +++ b/gst-plugin-closedcaption/tests/scc_enc.rs @@ -103,10 +103,10 @@ fn test_encode_multiple_packets() { gst::Fraction::new(30000, 1001), None, gst_video::VideoTimeCodeFlags::DROP_FRAME, - 00, - 00, - 00, - 00, + 0, + 0, + 0, + 0, 0, ) .unwrap(); @@ -115,10 +115,10 @@ fn test_encode_multiple_packets() { gst::Fraction::new(30000, 1001), None, gst_video::VideoTimeCodeFlags::DROP_FRAME, - 00, - 00, + 0, + 0, 14, - 01, + 1, 0, ) .unwrap(); @@ -200,8 +200,8 @@ fn test_encode_multiple_packets() { gst::Fraction::new(30000, 1001), None, gst_video::VideoTimeCodeFlags::DROP_FRAME, - 00, - 00, + 0, + 0, 14, 17, 0, diff --git a/gst-plugin-closedcaption/tests/scc_parse.rs b/gst-plugin-closedcaption/tests/scc_parse.rs index 15a20250..fa3797a4 100644 --- a/gst-plugin-closedcaption/tests/scc_parse.rs +++ b/gst-plugin-closedcaption/tests/scc_parse.rs @@ -90,9 +90,9 @@ fn test_parse() { ); } - assert_eq!(input_len, 241152); + assert_eq!(input_len, 241_152); assert_eq!(output_len, 89084); - assert_eq!(checksum, 12554799); + assert_eq!(checksum, 12_554_799); let caps = h .get_sinkpad() @@ -186,7 +186,7 @@ fn test_timecodes() { } assert_eq!(output_len, 1268); - assert_eq!(checksum, 174295); + assert_eq!(checksum, 174_295); let caps = h .get_sinkpad() diff --git a/gst-plugin-fallbackswitch/examples/gtk_fallbackswitch.rs b/gst-plugin-fallbackswitch/examples/gtk_fallbackswitch.rs index 21bc8925..ffb64542 100644 --- a/gst-plugin-fallbackswitch/examples/gtk_fallbackswitch.rs +++ b/gst-plugin-fallbackswitch/examples/gtk_fallbackswitch.rs @@ -161,10 +161,8 @@ fn create_ui(app: >k::Application) { *drop_id = video_src_pad .add_probe(gst::PadProbeType::BUFFER, |_, _| gst::PadProbeReturn::Drop); } - } else { - if let Some(drop_id) = drop_id.borrow_mut().take() { - video_src_pad.remove_probe(drop_id); - } + } else if let Some(drop_id) = drop_id.borrow_mut().take() { + video_src_pad.remove_probe(drop_id); } }); diff --git a/gst-plugin-fallbackswitch/tests/fallbackswitch.rs b/gst-plugin-fallbackswitch/tests/fallbackswitch.rs index 19b62498..20d45ae7 100644 --- a/gst-plugin-fallbackswitch/tests/fallbackswitch.rs +++ b/gst-plugin-fallbackswitch/tests/fallbackswitch.rs @@ -65,15 +65,15 @@ macro_rules! assert_buffer { fn test_no_fallback_no_drops() { let pipeline = setup_pipeline(None); - push_buffer(&pipeline, 0 * gst::SECOND); - set_time(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); + set_time(&pipeline, 0.into()); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); - push_buffer(&pipeline, 1 * gst::SECOND); - set_time(&pipeline, 1 * gst::SECOND); + push_buffer(&pipeline, gst::SECOND); + set_time(&pipeline, gst::SECOND); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 1 * gst::SECOND); + assert_buffer!(buffer, gst::SECOND); push_buffer(&pipeline, 2 * gst::SECOND); set_time(&pipeline, 2 * gst::SECOND); @@ -99,17 +99,17 @@ fn test_no_drops_not_live() { fn test_no_drops(live: bool) { let pipeline = setup_pipeline(Some(live)); - push_buffer(&pipeline, 0 * gst::SECOND); - push_fallback_buffer(&pipeline, 0 * gst::SECOND); - set_time(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); + push_fallback_buffer(&pipeline, 0.into()); + set_time(&pipeline, 0.into()); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); - push_fallback_buffer(&pipeline, 1 * gst::SECOND); - push_buffer(&pipeline, 1 * gst::SECOND); - set_time(&pipeline, 1 * gst::SECOND); + push_fallback_buffer(&pipeline, gst::SECOND); + push_buffer(&pipeline, gst::SECOND); + set_time(&pipeline, gst::SECOND); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 1 * gst::SECOND); + assert_buffer!(buffer, gst::SECOND); push_buffer(&pipeline, 2 * gst::SECOND); push_fallback_buffer(&pipeline, 2 * gst::SECOND); @@ -137,17 +137,17 @@ fn test_no_drops_but_no_fallback_frames_not_live() { fn test_no_drops_but_no_fallback_frames(live: bool) { let pipeline = setup_pipeline(Some(live)); - push_buffer(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); // +10ms needed here because the immediate timeout will be always at running time 0, but // aggregator also adds the latency to it so we end up at 10ms instead. - set_time(&pipeline, 0 * gst::SECOND + 10 * gst::MSECOND); + set_time(&pipeline, 10 * gst::MSECOND); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); - push_buffer(&pipeline, 1 * gst::SECOND); - set_time(&pipeline, 1 * gst::SECOND); + push_buffer(&pipeline, gst::SECOND); + set_time(&pipeline, gst::SECOND); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 1 * gst::SECOND); + assert_buffer!(buffer, gst::SECOND); push_buffer(&pipeline, 2 * gst::SECOND); set_time(&pipeline, 2 * gst::SECOND); @@ -174,17 +174,17 @@ fn test_short_drop_not_live() { fn test_short_drop(live: bool) { let pipeline = setup_pipeline(Some(live)); - push_buffer(&pipeline, 0 * gst::SECOND); - push_fallback_buffer(&pipeline, 0 * gst::SECOND); - set_time(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); + push_fallback_buffer(&pipeline, 0.into()); + set_time(&pipeline, 0.into()); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); // A timeout at 1s will get rid of the fallback buffer // but not output anything - push_fallback_buffer(&pipeline, 1 * gst::SECOND); + push_fallback_buffer(&pipeline, gst::SECOND); // Time out the fallback buffer at +10ms - set_time(&pipeline, 1 * gst::SECOND + 10 * gst::MSECOND); + set_time(&pipeline, gst::SECOND + 10 * gst::MSECOND); push_fallback_buffer(&pipeline, 2 * gst::SECOND); push_buffer(&pipeline, 2 * gst::SECOND); @@ -213,15 +213,15 @@ fn test_long_drop_and_eos(live: bool) { let pipeline = setup_pipeline(Some(live)); // Produce the first frame - push_buffer(&pipeline, 0 * gst::SECOND); - push_fallback_buffer(&pipeline, 0 * gst::SECOND); - set_time(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); + push_fallback_buffer(&pipeline, 0.into()); + set_time(&pipeline, 0.into()); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); // Produce a second frame but only from the fallback source - push_fallback_buffer(&pipeline, 1 * gst::SECOND); - set_time(&pipeline, 1 * gst::SECOND + 10 * gst::MSECOND); + push_fallback_buffer(&pipeline, gst::SECOND); + set_time(&pipeline, gst::SECOND + 10 * gst::MSECOND); // Produce a third frame but only from the fallback source push_fallback_buffer(&pipeline, 2 * gst::SECOND); @@ -263,15 +263,15 @@ fn test_long_drop_and_recover(live: bool) { let pipeline = setup_pipeline(Some(live)); // Produce the first frame - push_buffer(&pipeline, 0 * gst::SECOND); - push_fallback_buffer(&pipeline, 0 * gst::SECOND); - set_time(&pipeline, 0 * gst::SECOND); + push_buffer(&pipeline, 0.into()); + push_fallback_buffer(&pipeline, 0.into()); + set_time(&pipeline, 0.into()); let buffer = pull_buffer(&pipeline); - assert_buffer!(buffer, 0 * gst::SECOND); + assert_buffer!(buffer, 0.into()); // Produce a second frame but only from the fallback source - push_fallback_buffer(&pipeline, 1 * gst::SECOND); - set_time(&pipeline, 1 * gst::SECOND + 10 * gst::MSECOND); + push_fallback_buffer(&pipeline, gst::SECOND); + set_time(&pipeline, gst::SECOND + 10 * gst::MSECOND); // Produce a third frame but only from the fallback source push_fallback_buffer(&pipeline, 2 * gst::SECOND); @@ -339,14 +339,14 @@ fn setup_pipeline(with_live_fallback: Option) -> Pipeline { gst_debug!(TEST_CAT, "Setting up pipeline"); let clock = gst_check::TestClock::new(); - clock.set_time(0 * gst::SECOND); + clock.set_time(0.into()); let pipeline = gst::Pipeline::new(None); // Running time 0 in our pipeline is going to be clock time 1s. All // clock ids before 1s are used for signalling to our clock advancing // thread. pipeline.use_clock(Some(&clock)); - pipeline.set_base_time(1 * gst::SECOND); + pipeline.set_base_time(gst::SECOND); pipeline.set_start_time(gst::CLOCK_TIME_NONE); let src = gst::ElementFactory::make("appsrc", Some("src")) @@ -416,10 +416,7 @@ fn setup_pipeline(with_live_fallback: Option) -> Pipeline { pipeline.set_state(gst::State::Playing).unwrap(); - let clock_clone = clock.clone(); let clock_join_handle = std::thread::spawn(move || { - let clock = clock_clone; - loop { while let Some(clock_id) = clock.peek_next_pending_id().and_then(|clock_id| { // Process if the clock ID is in the past or now diff --git a/gst-plugin-reqwest/tests/reqwesthttpsrc.rs b/gst-plugin-reqwest/tests/reqwesthttpsrc.rs index 44652ec9..65f097d7 100644 --- a/gst-plugin-reqwest/tests/reqwesthttpsrc.rs +++ b/gst-plugin-reqwest/tests/reqwesthttpsrc.rs @@ -925,10 +925,7 @@ fn test_seek_after_ready() { }); let segment = h.wait_for_segment(false); - assert_eq!( - gst::format::Bytes::from(segment.get_start()), - gst::format::Bytes::from(123) - ); + assert_eq!(segment.get_start(), gst::format::Bytes::from(123)); let mut expected_output = vec![0; 8192 - 123]; for (i, d) in expected_output.iter_mut().enumerate() { @@ -1006,10 +1003,7 @@ fn test_seek_after_buffer_received() { }); let segment = h.wait_for_segment(true); - assert_eq!( - gst::format::Bytes::from(segment.get_start()), - gst::format::Bytes::from(123) - ); + assert_eq!(segment.get_start(), gst::format::Bytes::from(123)); let mut expected_output = vec![0; 8192 - 123]; for (i, d) in expected_output.iter_mut().enumerate() { @@ -1094,14 +1088,8 @@ fn test_seek_with_stop_position() { }); let segment = h.wait_for_segment(true); - assert_eq!( - gst::format::Bytes::from(segment.get_start()), - gst::format::Bytes::from(123) - ); - assert_eq!( - gst::format::Bytes::from(segment.get_stop()), - gst::format::Bytes::from(131) - ); + assert_eq!(segment.get_start(), gst::format::Bytes::from(123)); + assert_eq!(segment.get_stop(), gst::format::Bytes::from(131)); let mut expected_output = vec![0; 8]; for (i, d) in expected_output.iter_mut().enumerate() { diff --git a/gst-plugin-sodium/examples/generate_keys.rs b/gst-plugin-sodium/examples/generate_keys.rs index e0138697..b7de4777 100644 --- a/gst-plugin-sodium/examples/generate_keys.rs +++ b/gst-plugin-sodium/examples/generate_keys.rs @@ -48,9 +48,10 @@ impl Keys { path.into() }; - let file = File::create(&path).expect(&format!("Failed to create file at {}", path)); + let file = + File::create(&path).unwrap_or_else(|_| panic!("Failed to create file at {}", path)); serde_json::to_writer(file, &self) - .expect(&format!("Failed to write to file at {}", path)); + .unwrap_or_else(|_| panic!("Failed to write to file at {}", path)); } else { use std::io::Write; use std::path::PathBuf; @@ -58,16 +59,16 @@ impl Keys { let mut private = PathBuf::from(path); private.set_extension("prv"); let mut file = File::create(&private) - .expect(&format!("Failed to create file at {}", private.display())); + .unwrap_or_else(|_| panic!("Failed to create file at {}", private.display())); file.write_all(&self.private.0) - .expect(&format!("Failed to write to file at {}", private.display())); + .unwrap_or_else(|_| panic!("Failed to write to file at {}", private.display())); let mut public = PathBuf::from(path); public.set_extension("pub"); let mut file = File::create(&public) - .expect(&format!("Failed to create file at {}", public.display())); + .unwrap_or_else(|_| panic!("Failed to create file at {}", public.display())); file.write_all(self.public.as_ref()) - .expect(&format!("Failed to write to file at {}", public.display())); + .unwrap_or_else(|_| panic!("Failed to write to file at {}", public.display())); } } } diff --git a/gst-plugin-sodium/tests/decrypter.rs b/gst-plugin-sodium/tests/decrypter.rs index 6b9809e8..2fbb91e7 100644 --- a/gst-plugin-sodium/tests/decrypter.rs +++ b/gst-plugin-sodium/tests/decrypter.rs @@ -135,8 +135,7 @@ fn test_pipeline() { err.get_error() ); eprintln!("Debugging information: {:?}", err.get_debug()); - assert!(true); - break; + unreachable!(); } MessageView::Eos(..) => break, _ => (), @@ -268,7 +267,7 @@ fn test_pull_range() { assert_eq!(res, Err(gst::FlowError::Eos)); // read 100 bytes way past eos - let res = srcpad.get_range(424242, 100); + let res = srcpad.get_range(424_242, 100); assert_eq!(res, Err(gst::FlowError::Eos)); // read 10 bytes at eos -1, should return a single byte diff --git a/gst-plugin-threadshare/examples/tcpclientsrc_benchmark_sender.rs b/gst-plugin-threadshare/examples/tcpclientsrc_benchmark_sender.rs index ec86b8b9..435ba2c2 100644 --- a/gst-plugin-threadshare/examples/tcpclientsrc_benchmark_sender.rs +++ b/gst-plugin-threadshare/examples/tcpclientsrc_benchmark_sender.rs @@ -33,12 +33,11 @@ fn main() { let buffer = [0; 160]; let wait = time::Duration::from_millis(20); - let streams = sockets.clone(); loop { let now = time::Instant::now(); - for mut stream in streams.lock().unwrap().iter() { - let _ = stream.write(&buffer); + for mut socket in sockets.lock().unwrap().iter() { + let _ = socket.write(&buffer); } let elapsed = now.elapsed(); diff --git a/gst-plugin-threadshare/src/runtime/executor.rs b/gst-plugin-threadshare/src/runtime/executor.rs index bab65546..2ac4d330 100644 --- a/gst-plugin-threadshare/src/runtime/executor.rs +++ b/gst-plugin-threadshare/src/runtime/executor.rs @@ -372,11 +372,10 @@ mod tests { let sender: Arc>> = Arc::new(Mutex::new(sender)); let ctx_weak = context.downgrade(); - let queue_id_clone = queue_id.clone(); let add_task = move |item| { let sender_task = Arc::clone(&sender); let context = ctx_weak.upgrade().unwrap(); - context.add_task(queue_id_clone, async move { + context.add_task(queue_id, async move { sender_task .lock() .await diff --git a/gst-plugin-threadshare/tests/pipeline.rs b/gst-plugin-threadshare/tests/pipeline.rs index f04c96cb..1105d55a 100644 --- a/gst-plugin-threadshare/tests/pipeline.rs +++ b/gst-plugin-threadshare/tests/pipeline.rs @@ -142,13 +142,12 @@ fn multiple_contexts_queue() { match msg.view() { MessageView::StateChanged(state_changed) => { if let Some(source) = state_changed.get_src() { - if source.get_type() == gst::Pipeline::static_type() { - if state_changed.get_old() == gst::State::Paused - && state_changed.get_current() == gst::State::Playing - { - if let Some(test_scenario) = test_scenario.take() { - std::thread::spawn(test_scenario); - } + if source.get_type() == gst::Pipeline::static_type() + && state_changed.get_old() == gst::State::Paused + && state_changed.get_current() == gst::State::Playing + { + if let Some(test_scenario) = test_scenario.take() { + std::thread::spawn(test_scenario); } } } @@ -302,13 +301,12 @@ fn multiple_contexts_proxy() { match msg.view() { MessageView::StateChanged(state_changed) => { if let Some(source) = state_changed.get_src() { - if source.get_type() == gst::Pipeline::static_type() { - if state_changed.get_old() == gst::State::Paused - && state_changed.get_current() == gst::State::Playing - { - if let Some(test_scenario) = test_scenario.take() { - std::thread::spawn(test_scenario); - } + if source.get_type() == gst::Pipeline::static_type() + && state_changed.get_old() == gst::State::Paused + && state_changed.get_current() == gst::State::Playing + { + if let Some(test_scenario) = test_scenario.take() { + std::thread::spawn(test_scenario); } } } diff --git a/gst-plugin-threadshare/tests/tcpclientsrc.rs b/gst-plugin-threadshare/tests/tcpclientsrc.rs index 33e4b6ac..7498dcc7 100644 --- a/gst-plugin-threadshare/tests/tcpclientsrc.rs +++ b/gst-plugin-threadshare/tests/tcpclientsrc.rs @@ -48,14 +48,12 @@ fn test_push() { use std::net; let listener = net::TcpListener::bind("0.0.0.0:5000").unwrap(); - for stream in listener.incoming() { - let buffer = [0; 160]; - let mut socket = stream.unwrap(); - for _ in 0..3 { - let _ = socket.write(&buffer); - thread::sleep(time::Duration::from_millis(20)); - } - break; + let stream = listener.incoming().next().unwrap(); + let buffer = [0; 160]; + let mut socket = stream.unwrap(); + for _ in 0..3 { + let _ = socket.write(&buffer); + thread::sleep(time::Duration::from_millis(20)); } }); diff --git a/gst-plugin-togglerecord/tests/tests.rs b/gst-plugin-togglerecord/tests/tests.rs index 84219616..c0eaf674 100644 --- a/gst-plugin-togglerecord/tests/tests.rs +++ b/gst-plugin-togglerecord/tests/tests.rs @@ -46,6 +46,7 @@ enum SendData { Eos, } +#[allow(clippy::type_complexity)] fn setup_sender_receiver( pipeline: &gst::Pipeline, togglerecord: &gst::Element, diff --git a/gst-plugin-tutorial/src/sinesrc.rs b/gst-plugin-tutorial/src/sinesrc.rs index 60d175c0..8115391c 100644 --- a/gst-plugin-tutorial/src/sinesrc.rs +++ b/gst-plugin-tutorial/src/sinesrc.rs @@ -440,11 +440,13 @@ impl BaseSrcImpl for SineSrc { ) -> Result<(), gst::LoggableError> { use std::f64::consts::PI; - let info = gst_audio::AudioInfo::from_caps(caps).or(Err(gst_loggable_error!( - CAT, - "Failed to build `AudioInfo` from caps {}", - caps - )))?; + let info = gst_audio::AudioInfo::from_caps(caps).or_else(|_| { + Err(gst_loggable_error!( + CAT, + "Failed to build `AudioInfo` from caps {}", + caps + )) + })?; gst_debug!(CAT, obj: element, "Configuring for caps {}", caps);