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

feat(blink): refactor blink and improve call quality #376

Merged
merged 122 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 120 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
b4c664e
add handling for data channels
sdwoodbury Nov 2, 2023
f7961eb
Merge branch 'main' into feat/datachannels
sdwoodbury Nov 13, 2023
304e354
add back changes
sdwoodbury Nov 13, 2023
97b7423
disable the datachannel stuff for now
sdwoodbury Nov 14, 2023
ff2fbb4
simplify logic for mp4 logger
sdwoodbury Nov 14, 2023
87ce272
saving progress
sdwoodbury Nov 14, 2023
3c64e97
saving progress
sdwoodbury Nov 15, 2023
a5500dc
saving progress
sdwoodbury Nov 15, 2023
0cddfb0
move enum around
sdwoodbury Nov 15, 2023
0e7f1de
split audio controller into two files
sdwoodbury Nov 15, 2023
29b939a
wire up proxy
sdwoodbury Nov 15, 2023
3d4bb2e
wire up blink controller
sdwoodbury Nov 16, 2023
462fe68
use a notify in opus sink
sdwoodbury Nov 16, 2023
02ba073
fix clippy
sdwoodbury Nov 16, 2023
0b7c12c
use atomicbool in opussource
sdwoodbury Nov 16, 2023
efc876e
use atomicbool for automute
sdwoodbury Nov 16, 2023
c87c4d6
fix clippy
sdwoodbury Nov 16, 2023
ee0d3dc
update blink-repl
sdwoodbury Nov 16, 2023
2245994
fix clippy
sdwoodbury Nov 16, 2023
e2e1e3e
try to fix blink
sdwoodbury Nov 16, 2023
dc3ea22
fix wrong command in host_media::Controller
sdwoodbury Nov 16, 2023
b56d0c1
increase buffer size for opus sink and optimize decode_media_stream
sdwoodbury Nov 16, 2023
62b0b5e
use spawn_blocking insead of thread::spawn
sdwoodbury Nov 16, 2023
c5483d0
wire up notify to decode_media_stream
sdwoodbury Nov 16, 2023
8cdbf06
opus_sink: continue on invalid rtp packet
sdwoodbury Nov 16, 2023
69fb337
Merge branch 'main' into feat/datachannels
sdwoodbury Nov 16, 2023
c965aa5
chore: comment
sdwoodbury Nov 16, 2023
d9e81fb
wip: wire up tasks for audio source
sdwoodbury Nov 17, 2023
8280795
wip: decoder task
sdwoodbury Nov 20, 2023
8ff2678
saving progress
sdwoodbury Nov 20, 2023
7d0ed9a
remove resampler and audiohardwareconfig because the sampling rate is…
sdwoodbury Nov 20, 2023
be6769c
add the receiver task
sdwoodbury Nov 20, 2023
3234e22
rename
sdwoodbury Nov 21, 2023
3dc9244
add play and pause
sdwoodbury Nov 21, 2023
3fb49e6
wire up new sink track
sdwoodbury Nov 21, 2023
60e3925
rename sinktrack to sinktrackcontroller
sdwoodbury Nov 21, 2023
ebd8ac2
add function to chagne audio input device
sdwoodbury Nov 21, 2023
198b072
rename some stuff
sdwoodbury Nov 21, 2023
e8fc738
copy mp4logger over
sdwoodbury Nov 21, 2023
6c196d7
change back some stuff to the old hostmedia
sdwoodbury Nov 21, 2023
46631fd
fix some compiler errors
sdwoodbury Nov 21, 2023
4eabfc3
saving progress
sdwoodbury Nov 21, 2023
b14e63d
fix clippy
sdwoodbury Nov 21, 2023
5bffcfc
fix clippy
sdwoodbury Nov 21, 2023
7f2b713
fix cilppy
sdwoodbury Nov 21, 2023
2185f13
fix(blink): deal with hardware that doesn't use the requested buffer …
sdwoodbury Nov 21, 2023
9373293
Merge branch 'main' into feat/datachannels2
sdwoodbury Nov 21, 2023
a56f4c9
try to fix audio source again
sdwoodbury Nov 21, 2023
f4a7a74
try using a power of 2 for the audio buffer size
sdwoodbury Nov 21, 2023
204b25d
change opus_samples back to 480
sdwoodbury Nov 21, 2023
d48ff60
try memcpying from a vec instead of using channels
sdwoodbury Nov 21, 2023
de289df
fix use of copy_from_slice
sdwoodbury Nov 21, 2023
19eefcf
try changing the buffer sizes...
sdwoodbury Nov 21, 2023
63a76b9
change back to using a ringbuf
sdwoodbury Nov 22, 2023
e10a4a8
clean up imports
sdwoodbury Nov 22, 2023
d1b71ea
fix(audio sink): save new stream when changing audio device
sdwoodbury Nov 22, 2023
a8faa25
fix compiler errors:
sdwoodbury Nov 22, 2023
8a21b60
try to fix skipping effect
sdwoodbury Nov 22, 2023
457e5cd
wire up mp4_logger to source track
sdwoodbury Nov 22, 2023
151a7c7
wire up mp4 logger to sink track
sdwoodbury Nov 22, 2023
da6e8ee
fix complex type
sdwoodbury Nov 22, 2023
d3851da
fix import
sdwoodbury Nov 22, 2023
8748fe4
fix some clippy
sdwoodbury Nov 22, 2023
48262e1
fix clippy
sdwoodbury Nov 22, 2023
b1a6af4
fix clippy for real this time
sdwoodbury Nov 22, 2023
1329ebe
Merge branch 'main' into feat/datachannels2
sdwoodbury Nov 27, 2023
ad8d15a
add a dummy logger
sdwoodbury Nov 27, 2023
ee3c2ff
create way to change the mp4 logger
sdwoodbury Nov 27, 2023
8d1e35d
wire up mp4 logger
sdwoodbury Nov 27, 2023
838ebda
add back functionality to set peer volume
sdwoodbury Nov 28, 2023
e5d4a3d
move around some imports
sdwoodbury Nov 28, 2023
eb30be5
make a copy of simple_webrtc for modifications
sdwoodbury Nov 28, 2023
04593af
Revert "make a copy of simple_webrtc for modifications"
sdwoodbury Nov 28, 2023
70815eb
add sender task
sdwoodbury Nov 28, 2023
3472fe6
add receiver task
sdwoodbury Nov 28, 2023
8887826
switch the controller
sdwoodbury Nov 28, 2023
89d9159
add logging
sdwoodbury Nov 28, 2023
ce978c6
add more logging
sdwoodbury Nov 28, 2023
21deb4b
adding more logging
sdwoodbury Nov 28, 2023
d56279e
add delay
sdwoodbury Nov 28, 2023
03b9806
add more delay
sdwoodbury Nov 28, 2023
c74a449
remove delay
sdwoodbury Nov 28, 2023
f5a609b
remove logging
sdwoodbury Nov 28, 2023
057c58a
Merge branch 'main' into feat/blink-loopback
sdwoodbury Nov 29, 2023
2347a66
try to fix loopback test
sdwoodbury Nov 29, 2023
515b480
fix compiler
sdwoodbury Nov 29, 2023
0eda58e
write rtp with extensions
sdwoodbury Nov 29, 2023
4f0f787
add delay
sdwoodbury Nov 29, 2023
c5d7aa9
add regular controller back
sdwoodbury Nov 29, 2023
51f0f4f
make loopback configurable via a feature
sdwoodbury Nov 29, 2023
a33328b
make blink-repl use loopback
sdwoodbury Nov 29, 2023
2ed737f
comment out automute and speech detection briefly
sdwoodbury Nov 29, 2023
d5d56d9
try procesing received packets immediately
sdwoodbury Nov 29, 2023
66b5aa9
send decoder_task a vec instead of a Sample
sdwoodbury Nov 29, 2023
a3c5b27
increase size of heaprb
sdwoodbury Nov 29, 2023
a0d1b6f
add automute back
sdwoodbury Nov 29, 2023
bb9fa3b
don't send a fake loudness anymore
sdwoodbury Nov 29, 2023
10db1e6
make recveiver_task send a Sample instead of a vec again
sdwoodbury Nov 29, 2023
0ba38b4
Merge branch 'feat/blink-loopback2' into feat/datachannels2
sdwoodbury Nov 29, 2023
f18a215
fix mute, automute, and clippy
sdwoodbury Nov 29, 2023
21c1d6a
remove loopback feature from blink-repl
sdwoodbury Nov 29, 2023
7aafd49
wire up mute and unmute
sdwoodbury Nov 30, 2023
ea15e16
add automute back
sdwoodbury Nov 30, 2023
a27986b
wire up automute
sdwoodbury Nov 30, 2023
782e7ca
start and stop automute
sdwoodbury Nov 30, 2023
31c56b9
simplify automute code
sdwoodbury Nov 30, 2023
35600f8
add automute back to audio source
sdwoodbury Nov 30, 2023
a8267b5
simplify automute code some more
sdwoodbury Nov 30, 2023
04e80e6
don't pause cpal tracks to mute. rename pause and play to mute and un…
sdwoodbury Nov 30, 2023
5beaf98
pause track in audio device config
sdwoodbury Nov 30, 2023
f616f0a
add todos in audio-device-config
sdwoodbury Nov 30, 2023
b7ab69a
make AudioDeviceConfig use a oneshot channel to signal when done
sdwoodbury Nov 30, 2023
a847180
update blink-repl to use new AudioDeviceConfig
sdwoodbury Nov 30, 2023
f92a070
make audiodeviceconfig dynclone
sdwoodbury Nov 30, 2023
d81b6b3
uncomment set_peer_audio_gain
sdwoodbury Nov 30, 2023
909de8f
return event channel
sdwoodbury Dec 1, 2023
34663cf
use println in blink-repl
sdwoodbury Dec 1, 2023
a664cfd
Merge branch 'main' into feat/datachannels2
sdwoodbury Dec 1, 2023
40d2464
Merge branch 'main' into feat/datachannels2
dariusc93 Dec 3, 2023
7171489
Merge branch 'main' into feat/datachannels2
dariusc93 Dec 3, 2023
7c8d814
fix: code review
sdwoodbury Dec 4, 2023
47930ee
chore: remove type that vscode automatically added
sdwoodbury Dec 4, 2023
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
2 changes: 2 additions & 0 deletions extensions/warp-blink-wrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde_cbor = { workspace = true }
tokio = { workspace = true }
warp.workspace = true
webrtc = "0.6.0"
rayon = "1.8"

# media
cpal = "0.15.0"
Expand All @@ -41,3 +42,4 @@ cbindgen = "0.23"

[features]
build-header = []
loopback = []
160 changes: 62 additions & 98 deletions extensions/warp-blink-wrtc/src/blink_impl/blink_controller.rs

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions extensions/warp-blink-wrtc/src/blink_impl/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use warp::{
crypto::DID,
};

mod notify_wrapper;
pub use notify_wrapper::*;

#[derive(Clone)]
pub struct CallData {
pub info: CallInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use super::{
store::PeerIdExt,
};

use super::{data::NotifyWrapper, gossipsub_sender::GossipSubSender};
use super::gossipsub_sender::GossipSubSender;
use crate::notify_wrapper::NotifyWrapper;

enum GossipSubCmd {
// unsubscribe from the call and close any webrtc connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use warp::{

use super::store::{ecdh_decrypt, ecdh_encrypt};

use super::data::NotifyWrapper;
use crate::notify_wrapper::NotifyWrapper;

enum GossipSubCmd {
SendAes {
Expand Down
86 changes: 50 additions & 36 deletions extensions/warp-blink-wrtc/src/blink_impl/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod data;

mod blink_controller;
mod data;
mod gossipsub_listener;
mod gossipsub_sender;
mod signaling;
Expand All @@ -27,10 +26,7 @@ use warp::{

use crate::{
blink_impl::blink_controller::BlinkController,
host_media::{
self,
audio::automute::{AutoMuteCmd, AUDIO_CMD_CH},
},
host_media::{self, audio_utils::automute},
simple_webrtc::{self},
};

Expand All @@ -54,10 +50,9 @@ pub struct BlinkImpl {
struct DropHandler {}
impl Drop for DropHandler {
fn drop(&mut self) {
tokio::spawn(async move {
host_media::audio::automute::stop();
host_media::reset().await;
log::debug!("blink drop handler finished");
host_media::audio_utils::automute::stop();
tokio::spawn(async {
host_media::controller::reset().await;
});
}
}
Expand All @@ -66,20 +61,6 @@ impl BlinkImpl {
pub async fn new(account: Box<dyn MultiPass>) -> anyhow::Result<Box<Self>> {
log::trace!("initializing WebRTC");

let cpal_host = cpal::default_host();
if let Some(input_device) = cpal_host.default_input_device() {
host_media::change_audio_input(input_device).await?;
} else {
log::warn!("blink started with no input device");
}

if let Some(output_device) = cpal_host.default_output_device() {
host_media::change_audio_output(output_device).await?;
} else {
log::warn!("blink started with no output device");
}

// todo: ensure rx doesn't get dropped
let (ui_event_ch, _rx) = broadcast::channel(1024);
let (gossipsub_tx, gossipsub_rx) = mpsc::unbounded_channel();

Expand All @@ -102,7 +83,7 @@ impl BlinkImpl {

let blink_impl = Self {
own_id: Arc::new(warp::sync::RwLock::new(None)),
ui_event_ch,
ui_event_ch: ui_event_ch.clone(),
gossipsub_sender,
gossipsub_listener,
blink_controller,
Expand Down Expand Up @@ -140,6 +121,30 @@ impl BlinkImpl {
own_id.write().replace(public_did.clone());
ipfs.write().replace(_ipfs);

let cpal_host = cpal::default_host();
if let Some(input_device) = cpal_host.default_input_device() {
if let Err(e) = host_media::controller::change_audio_input(
&public_did,
input_device,
ui_event_ch.clone(),
)
.await
{
log::error!("BlinkImpl failed to set audio input device: {e}");
}
} else {
log::warn!("blink started with no input device");
}

if let Some(output_device) = cpal_host.default_output_device() {
if let Err(e) = host_media::controller::change_audio_output(output_device).await
{
log::error!("BlinkImpl failed to set audio output device: {e}");
}
} else {
log::warn!("blink started with no output device");
}

gossipsub_listener.receive_calls(public_did);
log::trace!("finished initializing WebRTC");
Ok(())
Expand All @@ -151,7 +156,7 @@ impl BlinkImpl {
}
});

host_media::audio::automute::start();
host_media::audio_utils::automute::start();
Ok(Box::new(blink_impl))
}

Expand All @@ -168,8 +173,15 @@ impl BlinkImpl {
r.ok_or(Error::AudioDeviceNotFound)?
};

host_media::change_audio_input(device).await?;
Ok(())
let opt = self.own_id.read().clone();
match opt {
Some(id) => {
host_media::controller::change_audio_input(&id, device, self.ui_event_ch.clone())
.await?;
Ok(())
}
None => Err(Error::BlinkNotInitialized),
}
}

async fn select_speaker(&mut self, device_name: &str) -> Result<(), Error> {
Expand All @@ -185,7 +197,7 @@ impl BlinkImpl {
r.ok_or(Error::AudioDeviceNotFound)?
};

host_media::change_audio_output(device).await?;
host_media::controller::change_audio_output(device).await?;
Ok(())
}
}
Expand Down Expand Up @@ -276,8 +288,10 @@ impl Blink for BlinkImpl {

// ------ Select input/output devices ------

async fn get_audio_device_config(&self) -> Box<dyn AudioDeviceConfig> {
Box::new(host_media::get_audio_device_config().await)
async fn get_audio_device_config(&self) -> Result<Box<dyn AudioDeviceConfig>, Error> {
Ok(Box::new(
host_media::controller::get_audio_device_config().await,
))
}

async fn set_audio_device_config(
Expand Down Expand Up @@ -338,18 +352,18 @@ impl Blink for BlinkImpl {
}

fn enable_automute(&mut self) -> Result<(), Error> {
let tx = AUDIO_CMD_CH.tx.clone();
tx.send(AutoMuteCmd::Enable)
let tx = automute::AUDIO_CMD_CH.tx.clone();
tx.send(automute::Cmd::Enable)
.map_err(|e| Error::OtherWithContext(format!("failed to enable automute: {e}")))
}
fn disable_automute(&mut self) -> Result<(), Error> {
let tx = AUDIO_CMD_CH.tx.clone();
tx.send(AutoMuteCmd::Disable)
let tx = automute::AUDIO_CMD_CH.tx.clone();
tx.send(automute::Cmd::Disable)
.map_err(|e| Error::OtherWithContext(format!("failed to disable automute: {e}")))
}

async fn set_peer_audio_gain(&mut self, peer_id: DID, multiplier: f32) -> Result<(), Error> {
host_media::set_peer_audio_gain(peer_id, multiplier).await?;
host_media::controller::set_peer_audio_gain(peer_id, multiplier).await;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/warp-blink-wrtc/src/blink_impl/signaling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub mod ipfs_routes {
use uuid::Uuid;
use warp::crypto::DID;

const TELECON_BROADCAST: &str = "telecon";
const OFFER_CALL: &str = "offer_call";
const TELECON_BROADCAST: &str = "telecon2";
const OFFER_CALL: &str = "offer_call2";
/// subscribe/unsubscribe per-call
/// CallSignal
pub fn call_signal_route(call_id: &Uuid) -> String {
Expand Down
107 changes: 0 additions & 107 deletions extensions/warp-blink-wrtc/src/host_media/audio/automute.rs

This file was deleted.

Loading
Loading