Skip to content

Commit

Permalink
add set_local_description
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Apr 21, 2024
1 parent 524b81e commit ba9c1fd
Show file tree
Hide file tree
Showing 7 changed files with 521 additions and 658 deletions.
239 changes: 105 additions & 134 deletions rtc/src/peer_connection/mod.rs

Large diffs are not rendered by default.

36 changes: 0 additions & 36 deletions rtc/src/peer_connection/peer_connection_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,42 +415,6 @@ impl PeerConnectionInternal {
self.trigger_negotiation_needed().await;
}

/// Helper to trigger a negotiation needed.
pub(crate) async fn trigger_negotiation_needed(&self) {
RTCPeerConnection::do_negotiation_needed(self.create_negotiation_needed_params()).await;
}

/// Creates the parameters needed to trigger a negotiation needed.
fn create_negotiation_needed_params(&self) -> NegotiationNeededParams {
NegotiationNeededParams {
on_negotiation_needed_handler: Arc::clone(&self.on_negotiation_needed_handler),
is_closed: Arc::clone(&self.is_closed),
ops: Arc::clone(&self.ops),
negotiation_needed_state: Arc::clone(&self.negotiation_needed_state),
is_negotiation_needed: Arc::clone(&self.is_negotiation_needed),
signaling_state: Arc::clone(&self.signaling_state),
check_negotiation_needed_params: CheckNegotiationNeededParams {
sctp_transport: Arc::clone(&self.sctp_transport),
rtp_transceivers: Arc::clone(&self.rtp_transceivers),
current_local_description: Arc::clone(&self.current_local_description),
current_remote_description: Arc::clone(&self.current_remote_description),
},
}
}

pub(crate) fn make_negotiation_needed_trigger(
&self,
) -> impl Fn() -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync {
let params = self.create_negotiation_needed_params();
move || {
let params = params.clone();
Box::pin(async move {
let params = params.clone();
RTCPeerConnection::do_negotiation_needed(params).await;
})
}
}

pub(super) fn set_gather_complete_handler(&self, f: OnGatheringCompleteHdlrFn) {
self.ice_gatherer.on_gathering_complete(f);
}
Expand Down
14 changes: 6 additions & 8 deletions rtc/src/peer_connection/sdp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use url::Url;
use crate::peer_connection::MEDIA_SECTION_APPLICATION;
use crate::transport::dtls_transport::dtls_fingerprint::RTCDtlsFingerprint;
use crate::transport::ice_transport::ice_candidate::RTCIceCandidate;
use crate::transport::ice_transport::ice_gatherer::RTCIceGatherer;
use crate::transport::ice_transport::ice_gathering_state::RTCIceGatheringState;
use crate::transport::ice_transport::ice_parameters::RTCIceParameters;
/*use crate::{SDP_ATTRIBUTE_RID, SDP_ATTRIBUTE_SIMULCAST};
Expand Down Expand Up @@ -398,21 +399,18 @@ pub(crate) fn add_data_media_section(

Ok(d.with_media(media))
}
/*

pub(crate) fn populate_local_candidates(
session_description: Option<&session_description::RTCSessionDescription>,
ice_gatherer: &RTCIceGatherer,
ice_gathering_state: RTCIceGatheringState,
) -> Option<session_description::RTCSessionDescription> {
if session_description.is_none() || ice_gatherer.is_none() {
if session_description.is_none() {
return session_description.cloned();
}

if let (Some(sd), Some(ice)) = (session_description, ice_gatherer) {
let candidates = match ice.get_local_candidates() {
Ok(candidates) => candidates,
Err(_) => return Some(sd.clone()),
};
if let Some(sd) = session_description {
let candidates = ice_gatherer.get_local_candidates();

let mut parsed = match sd.unmarshal() {
Ok(parsed) => parsed,
Expand All @@ -436,7 +434,7 @@ pub(crate) fn populate_local_candidates(
} else {
None
}
}*/
}

pub(crate) struct AddTransceiverSdpParams {
should_add_candidates: bool,
Expand Down
29 changes: 12 additions & 17 deletions rtc/src/rtp_transceiver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub type TriggerNegotiationNeededFnOption =
pub struct RTCRtpTransceiver {
mid: Option<String>,
sender: RTCRtpSender,
//todo: receiver: RTCRtpReceiver,
receiver: RTCRtpReceiver,
direction: RTCRtpTransceiverDirection,
current_direction: RTCRtpTransceiverDirection,

Expand Down Expand Up @@ -382,16 +382,16 @@ impl RTCRtpTransceiver {
);
}
}
/*

/// Perform any subsequent actions after altering the transceiver's direction.
///
/// After changing the transceiver's direction this method should be called to perform any
/// side-effects that results from the new direction, such as pausing/resuming the RTP receiver.
pub(crate) async fn process_new_current_direction(
&self,
pub(crate) fn process_new_current_direction(
&mut self,
previous_direction: RTCRtpTransceiverDirection,
) -> Result<()> {
if self.stopped.load(Ordering::SeqCst) {
if self.stopped {
return Ok(());
}

Expand All @@ -409,26 +409,21 @@ impl RTCRtpTransceiver {
return Ok(());
}

{
let receiver = self.receiver.lock().await;
let pause_receiver = !current_direction.has_recv();
let pause_receiver = !current_direction.has_recv();

if pause_receiver {
receiver.pause().await?;
} else {
receiver.resume().await?;
}
if pause_receiver {
self.receiver.pause()?;
} else {
self.receiver.resume()?;
}

let pause_sender = !current_direction.has_send();
{
let sender = &*self.sender.lock().await;
sender.set_paused(pause_sender);
}
self.sender.set_paused(pause_sender);

Ok(())
}

/*
/// stop irreversibly stops the RTPTransceiver
pub async fn stop(&self) -> Result<()> {
if self.stopped.load(Ordering::SeqCst) {
Expand Down
Loading

0 comments on commit ba9c1fd

Please sign in to comment.