Skip to content

Commit

Permalink
wip structs
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Oct 5, 2023
1 parent 327472c commit 5a9a2ee
Show file tree
Hide file tree
Showing 15 changed files with 682 additions and 22 deletions.
4 changes: 3 additions & 1 deletion Cargo.lock

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

6 changes: 6 additions & 0 deletions examples/wgpu_room/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ impl LkApp {
let _ = self.service.send(AsyncCmd::ToggleSine);
}
});

ui.menu_button("Debug", |ui| {
if ui.button("Refresh stats").clicked() {
let _ = self.service.send(AsyncCmd::RefreshStats);
}
});
});
}

Expand Down
6 changes: 6 additions & 0 deletions examples/wgpu_room/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum AsyncCmd {
publication: RemoteTrackPublication,
},
E2eeKeyRatchet,
RefreshStats,
}

#[derive(Debug)]
Expand Down Expand Up @@ -199,6 +200,11 @@ async fn service_task(inner: Arc<ServiceInner>, mut cmd_rx: mpsc::UnboundedRecei
}
}
}
AsyncCmd::RefreshStats => {
if let Some(state) = running_state.as_ref() {
state.room.get_stats();
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions libwebrtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ repository = "https://github.com/livekit/client-sdk-rust"
[dependencies]
livekit-protocol = { path = "../livekit-protocol", version = "0.2.0" }
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"

[target.'cfg(target_os = "android")'.dependencies]
Expand Down
10 changes: 6 additions & 4 deletions libwebrtc/src/data_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use crate::{imp::data_channel as dc_imp, rtp_parameters::Priority};
use serde::Deserialize;
use std::{fmt::Debug, str::Utf8Error};
use thiserror::Error;

Expand Down Expand Up @@ -49,8 +50,9 @@ pub enum DataChannelError {
Utf8(#[from] Utf8Error),
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DataState {
#[derive(Debug, Copy, Clone, PartialEq, Eq, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DataChannelState {
Connecting,
Open,
Closing,
Expand All @@ -63,7 +65,7 @@ pub struct DataBuffer<'a> {
pub binary: bool,
}

pub type OnStateChange = Box<dyn FnMut(DataState) + Send + Sync>;
pub type OnStateChange = Box<dyn FnMut(DataChannelState) + Send + Sync>;
pub type OnMessage = Box<dyn FnMut(DataBuffer) + Send + Sync>;
pub type OnBufferedAmountChange = Box<dyn FnMut(u64) + Send + Sync>;

Expand All @@ -85,7 +87,7 @@ impl DataChannel {
self.handle.label()
}

pub fn state(&self) -> DataState {
pub fn state(&self) -> DataChannelState {
self.handle.state()
}

Expand Down
1 change: 1 addition & 0 deletions libwebrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod rtp_receiver;
pub mod rtp_sender;
pub mod rtp_transceiver;
pub mod session_description;
pub mod stats;
pub mod video_frame;
pub mod video_source;
pub mod video_stream;
Expand Down
13 changes: 13 additions & 0 deletions libwebrtc/src/native/peer_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ use crate::rtp_receiver::RtpReceiver;
use crate::rtp_sender::RtpSender;
use crate::rtp_transceiver::RtpTransceiver;
use crate::rtp_transceiver::RtpTransceiverInit;
use crate::stats::RtcStats;
use crate::MediaType;
use crate::RtcErrorType;
use crate::{session_description::SessionDescription, RtcError};
use cxx::SharedPtr;
use parking_lot::Mutex;
use std::default;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::oneshot;
Expand Down Expand Up @@ -440,6 +442,17 @@ impl PeerConnection {
.map_err(|e| unsafe { sys_err::ffi::RtcError::from(e.what()).into() })
}

pub async fn get_stats(&self) -> Result<Vec<RtcStats>, RtcError> {
let (tx, rx) = oneshot::channel::<Result<Vec<RtcStats>, RtcError>>();
let ctx = Box::new(sys_pc::AsyncContext(Box::new(tx)));

self.sys_handle.get_stats(ctx, |ctx, stats| {
log::info!("Received stats {}", stats);
});

Ok(Default::default())
}

pub fn senders(&self) -> Vec<RtpSender> {
self.sys_handle
.get_senders()
Expand Down
6 changes: 6 additions & 0 deletions libwebrtc/src/peer_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::rtp_receiver::RtpReceiver;
use crate::rtp_sender::RtpSender;
use crate::rtp_transceiver::{RtpTransceiver, RtpTransceiverInit};
use crate::session_description::SessionDescription;
use crate::stats::RtcStats;
use crate::{MediaType, RtcError};
use std::fmt::Debug;

Expand Down Expand Up @@ -157,6 +158,10 @@ impl PeerConnection {
self.handle.remove_track(sender)
}

pub async fn get_stats(&self) -> Result<Vec<RtcStats>, RtcError> {
self.handle.get_stats().await
}

pub fn add_transceiver(
&self,
track: MediaStreamTrack,
Expand All @@ -172,6 +177,7 @@ impl PeerConnection {
) -> Result<RtpTransceiver, RtcError> {
self.handle.add_transceiver_for_media(media_type, init)
}

pub fn close(&self) {
self.handle.close()
}
Expand Down
Loading

0 comments on commit 5a9a2ee

Please sign in to comment.