Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using the boxfnonce library #415

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 6 additions & 9 deletions examples/simple_webrtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

Expand Down Expand Up @@ -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(),
);
}
}
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
Loading
Loading