Skip to content

Commit

Permalink
Stop using the boxfnonce library
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrobinson committed Jan 3, 2024
1 parent f29d18f commit 3c068f3
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 75 deletions.
30 changes: 10 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion audio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 12 additions & 13 deletions audio/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use boxfnonce::SendBoxFnOnce;
use std::sync::Mutex;

#[derive(Debug, PartialEq)]
Expand All @@ -16,10 +15,10 @@ pub enum AudioDecoderError {
}

pub struct AudioDecoderCallbacks {
pub eos: Mutex<Option<SendBoxFnOnce<'static, ()>>>,
pub error: Mutex<Option<SendBoxFnOnce<'static, (AudioDecoderError,)>>>,
pub eos: Mutex<Option<Box<dyn FnOnce() + Send + 'static>>>,
pub error: Mutex<Option<Box<dyn FnOnce(AudioDecoderError,) + Send + 'static>>>,
pub progress: Option<Box<dyn Fn(Box<dyn AsRef<[f32]>>, u32) + Send + Sync + 'static>>,
pub ready: Mutex<Option<SendBoxFnOnce<'static, (u32,)>>>,
pub ready: Mutex<Option<Box<dyn FnOnce(u32,) + Send + 'static>>>,
}

impl AudioDecoderCallbacks {
Expand All @@ -36,15 +35,15 @@ impl AudioDecoderCallbacks {
let eos = self.eos.lock().unwrap().take();
match eos {
None => return,
Some(callback) => callback.call(),
Some(callback) => callback(),
};
}

pub fn error(&self, error: AudioDecoderError) {
let callback = self.error.lock().unwrap().take();
match callback {
None => return,
Some(callback) => callback.call(error),
Some(callback) => callback(error),
};
}

Expand All @@ -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<SendBoxFnOnce<'static, ()>>,
error: Option<SendBoxFnOnce<'static, (AudioDecoderError,)>>,
eos: Option<Box<dyn FnOnce() + Send + 'static>>,
error: Option<Box<dyn FnOnce(AudioDecoderError,) + Send + 'static>>,
progress: Option<Box<dyn Fn(Box<dyn AsRef<[f32]>>, u32) + Send + Sync + 'static>>,
ready: Option<SendBoxFnOnce<'static, (u32,)>>,
ready: Option<Box<dyn FnOnce(u32,) + Send + 'static>>,
}

impl AudioDecoderCallbacksBuilder {
pub fn eos<F: FnOnce() + Send + 'static>(self, eos: F) -> Self {
Self {
eos: Some(SendBoxFnOnce::new(eos)),
eos: Some(Box::new(eos)),
..self
}
}

pub fn error<F: FnOnce(AudioDecoderError) + Send + 'static>(self, error: F) -> Self {
Self {
error: Some(SendBoxFnOnce::new(error)),
error: Some(Box::new(error)),
..self
}
}
Expand All @@ -98,7 +97,7 @@ impl AudioDecoderCallbacksBuilder {

pub fn ready<F: FnOnce(u32) + Send + 'static>(self, ready: F) -> Self {
Self {
ready: Some(SendBoxFnOnce::new(ready)),
ready: Some(Box::new(ready)),
..self
}
}
Expand Down
1 change: 0 additions & 1 deletion audio/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions audio/node.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -204,11 +203,11 @@ pub enum AudioNodeMessage {
WaveShaperNode(WaveShaperNodeMessage),
}

pub struct OnEndedCallback(pub SendBoxFnOnce<'static, ()>);
pub struct OnEndedCallback(pub Box<dyn FnOnce() + Send + 'static>);

impl OnEndedCallback {
pub fn new<F: FnOnce() + Send + 'static>(callback: F) -> Self {
OnEndedCallback(SendBoxFnOnce::new(callback))
OnEndedCallback(Box::new(callback))
}
}

Expand Down
1 change: 0 additions & 1 deletion backends/dummy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 4 additions & 6 deletions backends/dummy/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate boxfnonce;
extern crate ipc_channel;
extern crate servo_media;
extern crate servo_media_audio;
Expand All @@ -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};
Expand Down Expand Up @@ -288,24 +286,24 @@ impl WebRtcControllerBackend for DummyWebRtcController {
fn set_remote_description(
&mut self,
_: SessionDescription,
_: SendBoxFnOnce<'static, ()>,
_: Box<dyn FnOnce() + Send + 'static>,
) -> WebRtcResult {
Ok(())
}
fn set_local_description(
&mut self,
_: SessionDescription,
_: SendBoxFnOnce<'static, ()>,
_: Box<dyn FnOnce() + Send + 'static>,
) -> 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<dyn FnOnce(SessionDescription) + Send + 'static>) -> WebRtcResult {
Ok(())
}
fn create_answer(&mut self, _: SendBoxFnOnce<'static, (SessionDescription,)>) -> WebRtcResult {
fn create_answer(&mut self, _: Box<dyn FnOnce(SessionDescription) + Send + 'static>) -> WebRtcResult {
Ok(())
}
fn add_stream(&mut self, _: &MediaStreamId) -> WebRtcResult {
Expand Down
1 change: 0 additions & 1 deletion backends/gstreamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 8 additions & 9 deletions backends/gstreamer/webrtc.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -97,20 +96,20 @@ impl WebRtcControllerBackend for GStreamerWebRtcController {
fn set_remote_description(
&mut self,
desc: SessionDescription,
cb: SendBoxFnOnce<'static, ()>,
cb: Box<dyn FnOnce() + Send + 'static>,
) -> WebRtcResult {
self.set_description(desc, DescriptionType::Remote, cb)
}

fn set_local_description(
&mut self,
desc: SessionDescription,
cb: SendBoxFnOnce<'static, ()>,
cb: Box<dyn FnOnce() + Send + 'static>,
) -> 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<dyn FnOnce(SessionDescription) + Send + 'static>) -> WebRtcResult {
self.flush_pending_streams(true)?;
self.pipeline.set_state(gst::State::Playing)?;
let promise = gst::Promise::with_change_func(move |res| {
Expand All @@ -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<dyn FnOnce(SessionDescription) + Send + 'static>) -> WebRtcResult {
let promise = gst::Promise::with_change_func(move |res| {
res.map(|s| on_offer_or_answer_created(SdpType::Answer, s.unwrap(), cb))
.unwrap();
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -339,7 +338,7 @@ impl GStreamerWebRtcController {
&mut self,
desc: SessionDescription,
description_type: DescriptionType,
cb: SendBoxFnOnce<'static, ()>,
cb: Box<dyn FnOnce() + Send + 'static>,
) -> WebRtcResult {
let ty = match desc.type_ {
SdpType::Answer => gst_webrtc::WebRTCSDPType::Answer,
Expand Down Expand Up @@ -676,7 +675,7 @@ pub fn construct(
fn on_offer_or_answer_created(
ty: SdpType,
reply: &gst::StructureRef,
cb: SendBoxFnOnce<'static, (SessionDescription,)>,
cb: Box<dyn FnOnce(SessionDescription) + Send + 'static>,
) {
debug_assert!(ty == SdpType::Offer || ty == SdpType::Answer);
let reply = reply
Expand All @@ -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<Mutex<WebRtcThread>>, pad: &gst::Pad) {
Expand Down
2 changes: 1 addition & 1 deletion servo-media-derive/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
1 change: 0 additions & 1 deletion webrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
11 changes: 4 additions & 7 deletions webrtc/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate boxfnonce;
extern crate log;
extern crate servo_media_streams;
extern crate uuid;
Expand All @@ -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;

Expand Down Expand Up @@ -40,16 +37,16 @@ pub trait WebRtcControllerBackend: Send {
fn set_remote_description(
&mut self,
_: SessionDescription,
cb: SendBoxFnOnce<'static, ()>,
cb: Box<dyn FnOnce() + Send + 'static>,
) -> WebRtcResult;
fn set_local_description(
&mut self,
_: SessionDescription,
cb: SendBoxFnOnce<'static, ()>,
cb: Box<dyn FnOnce() + Send + 'static>,
) -> 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<dyn FnOnce(SessionDescription,) + Send + 'static>) -> WebRtcResult;
fn create_answer(&mut self, cb: Box<dyn FnOnce(SessionDescription,) + Send + 'static>) -> WebRtcResult;
fn add_stream(&mut self, stream: &MediaStreamId) -> WebRtcResult;

fn create_data_channel(&mut self, init: &DataChannelInit) -> WebRtcDataChannelResult;
Expand Down
Loading

0 comments on commit 3c068f3

Please sign in to comment.