From 999920a656e4100c9029250385da4f5b1fd8f49e Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Wed, 3 Jan 2024 12:04:27 +0100 Subject: [PATCH] Stop using the `boxfnonce` library This is no longer necessary in modern versions of Rust and the library is now unmaintained. See https://blog.rust-lang.org/2019/05/23/Rust-1.35.0.html#fn-closure-traits-implemented-for-box%3Cdyn-fn*%3E --- Cargo.lock | 30 ++++++++++-------------------- audio/Cargo.toml | 1 - audio/decoder.rs | 25 ++++++++++++------------- audio/lib.rs | 1 - audio/node.rs | 5 ++--- backends/dummy/Cargo.toml | 1 - backends/dummy/lib.rs | 10 ++++------ backends/gstreamer/Cargo.toml | 1 - backends/gstreamer/webrtc.rs | 17 ++++++++--------- examples/simple_webrtc.rs | 15 ++++++--------- servo-media-derive/lib.rs | 2 +- webrtc/Cargo.toml | 1 - webrtc/lib.rs | 11 ++++------- webrtc/thread.rs | 20 +++++++++----------- 14 files changed, 56 insertions(+), 84 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dc5b584..3bd96659 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,12 +151,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "boxfnonce" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5988cb1d626264ac94100be357308f29ff7cbdd3b36bda27f450a4ee3f713426" - [[package]] name = "build-parallel" version = "0.1.2" @@ -2510,7 +2504,6 @@ dependencies = [ name = "servo-media-audio" version = "0.2.0" dependencies = [ - "boxfnonce", "byte-slice-cast", "euclid", "log 0.4.17", @@ -2519,10 +2512,10 @@ dependencies = [ "petgraph", "serde", "serde_derive", + "servo-media-derive", "servo-media-player", "servo-media-streams", "servo-media-traits", - "servo_media_derive", "smallvec 1.10.0", "speexdsp-resampler", ] @@ -2535,11 +2528,19 @@ dependencies = [ "servo-media-gstreamer", ] +[[package]] +name = "servo-media-derive" +version = "0.1.0" +dependencies = [ + "proc-macro2 1.0.64", + "quote 1.0.29", + "syn 1.0.107", +] + [[package]] name = "servo-media-dummy" version = "0.1.0" dependencies = [ - "boxfnonce", "ipc-channel", "servo-media", "servo-media-audio", @@ -2553,7 +2554,6 @@ dependencies = [ name = "servo-media-gstreamer" version = "0.1.0" dependencies = [ - "boxfnonce", "byte-slice-cast", "glib", "glib-sys", @@ -2647,7 +2647,6 @@ version = "0.1.0" name = "servo-media-webrtc" version = "0.1.0" dependencies = [ - "boxfnonce", "lazy_static", "log 0.4.17", "servo-media-streams", @@ -2663,15 +2662,6 @@ dependencies = [ "servo-media-auto", ] -[[package]] -name = "servo_media_derive" -version = "0.1.0" -dependencies = [ - "proc-macro2 1.0.64", - "quote 1.0.29", - "syn 1.0.107", -] - [[package]] name = "sha1" version = "0.6.1" diff --git a/audio/Cargo.toml b/audio/Cargo.toml index a465f3a6..65b5c6e8 100644 --- a/audio/Cargo.toml +++ b/audio/Cargo.toml @@ -9,7 +9,6 @@ name = "servo_media_audio" path = "lib.rs" [dependencies] -boxfnonce = "0.1" euclid = "0.22" log = "0.4" serde_derive = "1.0.66" diff --git a/audio/decoder.rs b/audio/decoder.rs index 99235b1e..73c9b712 100644 --- a/audio/decoder.rs +++ b/audio/decoder.rs @@ -1,4 +1,3 @@ -use boxfnonce::SendBoxFnOnce; use std::sync::Mutex; #[derive(Debug, PartialEq)] @@ -16,10 +15,10 @@ pub enum AudioDecoderError { } pub struct AudioDecoderCallbacks { - pub eos: Mutex>>, - pub error: Mutex>>, + pub eos: Mutex>>, + pub error: Mutex>>, pub progress: Option>, u32) + Send + Sync + 'static>>, - pub ready: Mutex>>, + pub ready: Mutex>>, } impl AudioDecoderCallbacks { @@ -36,7 +35,7 @@ impl AudioDecoderCallbacks { let eos = self.eos.lock().unwrap().take(); match eos { None => return, - Some(callback) => callback.call(), + Some(callback) => callback(), }; } @@ -44,7 +43,7 @@ impl AudioDecoderCallbacks { let callback = self.error.lock().unwrap().take(); match callback { None => return, - Some(callback) => callback.call(error), + Some(callback) => callback(error), }; } @@ -59,29 +58,29 @@ impl AudioDecoderCallbacks { let ready = self.ready.lock().unwrap().take(); match ready { None => return, - Some(callback) => callback.call(channels), + Some(callback) => callback(channels), }; } } pub struct AudioDecoderCallbacksBuilder { - eos: Option>, - error: Option>, + eos: Option>, + error: Option>, progress: Option>, u32) + Send + Sync + 'static>>, - ready: Option>, + ready: Option>, } impl AudioDecoderCallbacksBuilder { pub fn eos(self, eos: F) -> Self { Self { - eos: Some(SendBoxFnOnce::new(eos)), + eos: Some(Box::new(eos)), ..self } } pub fn error(self, error: F) -> Self { Self { - error: Some(SendBoxFnOnce::new(error)), + error: Some(Box::new(error)), ..self } } @@ -98,7 +97,7 @@ impl AudioDecoderCallbacksBuilder { pub fn ready(self, ready: F) -> Self { Self { - ready: Some(SendBoxFnOnce::new(ready)), + ready: Some(Box::new(ready)), ..self } } diff --git a/audio/lib.rs b/audio/lib.rs index 50665804..ff7de54a 100644 --- a/audio/lib.rs +++ b/audio/lib.rs @@ -6,7 +6,6 @@ extern crate servo_media_derive; extern crate servo_media_player as player; -extern crate boxfnonce; extern crate byte_slice_cast; extern crate euclid; extern crate log; diff --git a/audio/node.rs b/audio/node.rs index 67fb8d6d..0f60d220 100644 --- a/audio/node.rs +++ b/audio/node.rs @@ -1,6 +1,5 @@ use biquad_filter_node::{BiquadFilterNodeMessage, BiquadFilterNodeOptions}; use block::{Block, Chunk, Tick}; -use boxfnonce::SendBoxFnOnce; use buffer_source_node::{AudioBufferSourceNodeMessage, AudioBufferSourceNodeOptions}; use channel_node::ChannelNodeOptions; use constant_source_node::ConstantSourceNodeOptions; @@ -204,11 +203,11 @@ pub enum AudioNodeMessage { WaveShaperNode(WaveShaperNodeMessage), } -pub struct OnEndedCallback(pub SendBoxFnOnce<'static, ()>); +pub struct OnEndedCallback(pub Box); impl OnEndedCallback { pub fn new(callback: F) -> Self { - OnEndedCallback(SendBoxFnOnce::new(callback)) + OnEndedCallback(Box::new(callback)) } } diff --git a/backends/dummy/Cargo.toml b/backends/dummy/Cargo.toml index e369a4ba..32f30a22 100644 --- a/backends/dummy/Cargo.toml +++ b/backends/dummy/Cargo.toml @@ -9,7 +9,6 @@ name = "servo_media_dummy" path = "lib.rs" [dependencies] -boxfnonce = "0.1.0" ipc-channel = { workspace = true } servo-media = { path = "../../servo-media" } servo-media-audio = { path = "../../audio" } diff --git a/backends/dummy/lib.rs b/backends/dummy/lib.rs index 35d0a30e..89319bbb 100644 --- a/backends/dummy/lib.rs +++ b/backends/dummy/lib.rs @@ -1,4 +1,3 @@ -extern crate boxfnonce; extern crate ipc_channel; extern crate servo_media; extern crate servo_media_audio; @@ -7,7 +6,6 @@ extern crate servo_media_streams; extern crate servo_media_traits; extern crate servo_media_webrtc; -use boxfnonce::SendBoxFnOnce; use ipc_channel::ipc::IpcSender; use servo_media::{Backend, BackendInit, SupportsMediaType}; use servo_media_audio::block::{Block, Chunk}; @@ -288,24 +286,24 @@ impl WebRtcControllerBackend for DummyWebRtcController { fn set_remote_description( &mut self, _: SessionDescription, - _: SendBoxFnOnce<'static, ()>, + _: Box, ) -> WebRtcResult { Ok(()) } fn set_local_description( &mut self, _: SessionDescription, - _: SendBoxFnOnce<'static, ()>, + _: Box, ) -> WebRtcResult { Ok(()) } fn add_ice_candidate(&mut self, _: IceCandidate) -> WebRtcResult { Ok(()) } - fn create_offer(&mut self, _: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult { + fn create_offer(&mut self, _: Box) -> WebRtcResult { Ok(()) } - fn create_answer(&mut self, _: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult { + fn create_answer(&mut self, _: Box) -> WebRtcResult { Ok(()) } fn add_stream(&mut self, _: &MediaStreamId) -> WebRtcResult { diff --git a/backends/gstreamer/Cargo.toml b/backends/gstreamer/Cargo.toml index 260111b0..7a7982ee 100644 --- a/backends/gstreamer/Cargo.toml +++ b/backends/gstreamer/Cargo.toml @@ -10,7 +10,6 @@ name = "servo_media_gstreamer" path = "lib.rs" [dependencies] -boxfnonce = "0.1.0" byte-slice-cast = "0.2" glib = "0.18" glib-sys = "0.18" diff --git a/backends/gstreamer/webrtc.rs b/backends/gstreamer/webrtc.rs index 0ef2853c..77bb5987 100644 --- a/backends/gstreamer/webrtc.rs +++ b/backends/gstreamer/webrtc.rs @@ -1,7 +1,6 @@ use super::BACKEND_BASE_TIME; use crate::datachannel::GStreamerWebRtcDataChannel; use crate::media_stream::GStreamerMediaStream; -use boxfnonce::SendBoxFnOnce; use glib; use glib::prelude::*; use gst; @@ -97,7 +96,7 @@ impl WebRtcControllerBackend for GStreamerWebRtcController { fn set_remote_description( &mut self, desc: SessionDescription, - cb: SendBoxFnOnce<'static, ()>, + cb: Box, ) -> WebRtcResult { self.set_description(desc, DescriptionType::Remote, cb) } @@ -105,12 +104,12 @@ impl WebRtcControllerBackend for GStreamerWebRtcController { fn set_local_description( &mut self, desc: SessionDescription, - cb: SendBoxFnOnce<'static, ()>, + cb: Box, ) -> WebRtcResult { self.set_description(desc, DescriptionType::Local, cb) } - fn create_offer(&mut self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult { + fn create_offer(&mut self, cb: Box) -> WebRtcResult { self.flush_pending_streams(true)?; self.pipeline.set_state(gst::State::Playing)?; let promise = gst::Promise::with_change_func(move |res| { @@ -123,7 +122,7 @@ impl WebRtcControllerBackend for GStreamerWebRtcController { Ok(()) } - fn create_answer(&mut self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult { + fn create_answer(&mut self, cb: Box) -> WebRtcResult { let promise = gst::Promise::with_change_func(move |res| { res.map(|s| on_offer_or_answer_created(SdpType::Answer, s.unwrap(), cb)) .unwrap(); @@ -260,7 +259,7 @@ impl WebRtcControllerBackend for GStreamerWebRtcController { self.flush_pending_streams(false)?; } self.pipeline.set_state(gst::State::Playing)?; - cb.call(); + cb(); } InternalEvent::UpdateSignalingState => { use gst_webrtc::WebRTCSignalingState::*; @@ -339,7 +338,7 @@ impl GStreamerWebRtcController { &mut self, desc: SessionDescription, description_type: DescriptionType, - cb: SendBoxFnOnce<'static, ()>, + cb: Box, ) -> WebRtcResult { let ty = match desc.type_ { SdpType::Answer => gst_webrtc::WebRTCSDPType::Answer, @@ -676,7 +675,7 @@ pub fn construct( fn on_offer_or_answer_created( ty: SdpType, reply: &gst::StructureRef, - cb: SendBoxFnOnce<'static, (SessionDescription,)>, + cb: Box, ) { debug_assert!(ty == SdpType::Offer || ty == SdpType::Answer); let reply = reply @@ -698,7 +697,7 @@ fn on_offer_or_answer_created( type_, }; - cb.call(desc); + cb(desc); } fn on_incoming_stream(pipe: &gst::Pipeline, thread: Arc>, pad: &gst::Pad) { diff --git a/examples/simple_webrtc.rs b/examples/simple_webrtc.rs index c24e1342..394eca89 100644 --- a/examples/simple_webrtc.rs +++ b/examples/simple_webrtc.rs @@ -187,10 +187,9 @@ impl WebRtcSignaller for Signaller { let c2 = controller.clone(); let s2 = self.clone(); controller.create_offer( - (move |offer: SessionDescription| { - c2.set_local_description(offer.clone(), (move || s2.send_sdp(offer)).into()) + Box::new(move |offer: SessionDescription| { + c2.set_local_description(offer.clone(), Box::new(move || s2.send_sdp(offer))) }) - .into(), ); } @@ -300,25 +299,23 @@ fn receive_loop( }; let controller = state.webrtc.as_ref().unwrap(); if state.peer_id.is_some() { - controller.set_remote_description(desc, (|| {}).into()); + controller.set_remote_description(desc, Box::new(|| {})); } else { let c2 = controller.clone(); let c3 = controller.clone(); let s2 = state.signaller.clone().unwrap(); controller.set_remote_description( desc, - (move || { + Box::new(move || { c3.create_answer( - (move |answer: SessionDescription| { + Box::new(move |answer: SessionDescription| { c2.set_local_description( answer.clone(), - (move || s2.send_sdp(answer)).into(), + Box::new(move || s2.send_sdp(answer)), ) }) - .into(), ) }) - .into(), ); } } diff --git a/servo-media-derive/lib.rs b/servo-media-derive/lib.rs index 1a347bf3..629c1f40 100644 --- a/servo-media-derive/lib.rs +++ b/servo-media-derive/lib.rs @@ -92,7 +92,7 @@ fn impl_audio_scheduled_source_node(ast: &syn::DeriveInput) -> proc_macro2::Toke return; } if let Some(cb) = self.onended_callback.take() { - cb.0.call() + cb.0() } } diff --git a/webrtc/Cargo.toml b/webrtc/Cargo.toml index a8347545..b6219597 100644 --- a/webrtc/Cargo.toml +++ b/webrtc/Cargo.toml @@ -8,7 +8,6 @@ license = "MPL-2.0" path = "lib.rs" [dependencies] -boxfnonce = "0.1.0" lazy_static = "1.0" log = "0.4.6" uuid = { version = "1.4", features = ["v4"] } diff --git a/webrtc/lib.rs b/webrtc/lib.rs index 847fd980..4e63d4aa 100644 --- a/webrtc/lib.rs +++ b/webrtc/lib.rs @@ -1,4 +1,3 @@ -extern crate boxfnonce; extern crate log; extern crate servo_media_streams; extern crate uuid; @@ -9,8 +8,6 @@ use servo_media_streams::MediaStreamType; use std::fmt::Display; use std::str::FromStr; -use boxfnonce::SendBoxFnOnce; - pub mod datachannel; pub mod thread; @@ -40,16 +37,16 @@ pub trait WebRtcControllerBackend: Send { fn set_remote_description( &mut self, _: SessionDescription, - cb: SendBoxFnOnce<'static, ()>, + cb: Box, ) -> WebRtcResult; fn set_local_description( &mut self, _: SessionDescription, - cb: SendBoxFnOnce<'static, ()>, + cb: Box, ) -> WebRtcResult; fn add_ice_candidate(&mut self, candidate: IceCandidate) -> WebRtcResult; - fn create_offer(&mut self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult; - fn create_answer(&mut self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult; + fn create_offer(&mut self, cb: Box) -> WebRtcResult; + fn create_answer(&mut self, cb: Box) -> WebRtcResult; fn add_stream(&mut self, stream: &MediaStreamId) -> WebRtcResult; fn create_data_channel(&mut self, init: &DataChannelInit) -> WebRtcDataChannelResult; diff --git a/webrtc/thread.rs b/webrtc/thread.rs index 61740390..2932d579 100644 --- a/webrtc/thread.rs +++ b/webrtc/thread.rs @@ -3,8 +3,6 @@ use std::thread; use log::error; -use boxfnonce::SendBoxFnOnce; - use crate::datachannel::{DataChannelEvent, DataChannelId, DataChannelInit, DataChannelMessage}; use crate::{ BundlePolicy, DescriptionType, IceCandidate, MediaStreamId, SdpType, SessionDescription, @@ -43,12 +41,12 @@ impl WebRtcController { .sender .send(RtcThreadEvent::ConfigureStun(stun_server, policy)); } - pub fn set_remote_description(&self, desc: SessionDescription, cb: SendBoxFnOnce<'static, ()>) { + pub fn set_remote_description(&self, desc: SessionDescription, cb: Box) { let _ = self .sender .send(RtcThreadEvent::SetRemoteDescription(desc, cb)); } - pub fn set_local_description(&self, desc: SessionDescription, cb: SendBoxFnOnce<'static, ()>) { + pub fn set_local_description(&self, desc: SessionDescription, cb: Box) { let _ = self .sender .send(RtcThreadEvent::SetLocalDescription(desc, cb)); @@ -56,10 +54,10 @@ impl WebRtcController { pub fn add_ice_candidate(&self, candidate: IceCandidate) { let _ = self.sender.send(RtcThreadEvent::AddIceCandidate(candidate)); } - pub fn create_offer(&self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) { + pub fn create_offer(&self, cb: Box) { let _ = self.sender.send(RtcThreadEvent::CreateOffer(cb)); } - pub fn create_answer(&self, cb: SendBoxFnOnce<'static, (SessionDescription,)>) { + pub fn create_answer(&self, cb: Box) { let _ = self.sender.send(RtcThreadEvent::CreateAnswer(cb)); } pub fn add_stream(&self, stream: &MediaStreamId) { @@ -93,11 +91,11 @@ impl WebRtcController { pub enum RtcThreadEvent { ConfigureStun(String, BundlePolicy), - SetRemoteDescription(SessionDescription, SendBoxFnOnce<'static, ()>), - SetLocalDescription(SessionDescription, SendBoxFnOnce<'static, ()>), + SetRemoteDescription(SessionDescription, Box), + SetLocalDescription(SessionDescription, Box), AddIceCandidate(IceCandidate), - CreateOffer(SendBoxFnOnce<'static, (SessionDescription,)>), - CreateAnswer(SendBoxFnOnce<'static, (SessionDescription,)>), + CreateOffer(Box), + CreateAnswer(Box), AddStream(MediaStreamId), CreateDataChannel(DataChannelInit, Sender>), CloseDataChannel(DataChannelId), @@ -117,7 +115,7 @@ pub enum InternalEvent { OnAddStream(MediaStreamId, MediaStreamType), OnDataChannelEvent(DataChannelId, DataChannelEvent), DescriptionAdded( - SendBoxFnOnce<'static, ()>, + Box, DescriptionType, SdpType, /* remote offer generation */ u32,