Skip to content

Commit ce3a4ad

Browse files
committed
refactoring pc closing err
1 parent 23c843b commit ce3a4ad

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ ice = { package = "webrtc-ice", version = "0.5.1" }
2121
dtls = { package = "webrtc-dtls", version = "0.5.0" }
2222
rtp = "0.6.1"
2323
rtcp = "0.6.1"
24-
srtp = { package = "webrtc-srtp", version = "0.8.3" }
24+
srtp = { package = "webrtc-srtp", version = "0.8.4" }
2525
sctp = { package = "webrtc-sctp", version = "0.4.1" }
2626
data = { package = "webrtc-data", version = "0.3.1" }
2727
media = { package = "webrtc-media", version = "0.4.1" }
28-
interceptor = "0.7.0"
28+
interceptor = "0.7.1"
2929
tokio = { version = "1.12.0", features = ["full"] }
3030
log = "0.4.14"
3131
async-trait = "0.1.42"

src/dtls_transport/mod.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::HashMap;
12
use std::future::Future;
23
use std::pin::Pin;
34
use std::sync::atomic::{AtomicBool, AtomicU8, Ordering};
@@ -73,7 +74,7 @@ pub struct RTCDtlsTransport {
7374
pub(crate) srtp_endpoint: Mutex<Option<Arc<Endpoint>>>,
7475
pub(crate) srtcp_endpoint: Mutex<Option<Arc<Endpoint>>>,
7576

76-
pub(crate) simulcast_streams: Mutex<Vec<Arc<Stream>>>,
77+
pub(crate) simulcast_streams: Mutex<HashMap<SSRC, Arc<Stream>>>,
7778

7879
pub(crate) srtp_ready_signal: Arc<AtomicBool>,
7980
pub(crate) srtp_ready_tx: Mutex<Option<mpsc::Sender<()>>>,
@@ -488,13 +489,17 @@ impl RTCDtlsTransport {
488489
{
489490
let simulcast_streams: Vec<Arc<Stream>> = {
490491
let mut simulcast_streams = self.simulcast_streams.lock().await;
491-
simulcast_streams.drain(..).collect()
492+
simulcast_streams.drain().map(|(_, v)| v).collect()
492493
};
493494
for ss in simulcast_streams {
494495
match ss.close().await {
495496
Ok(_) => {}
496497
Err(err) => {
497-
close_errs.push(err.into());
498+
close_errs.push(Error::new(format!(
499+
"simulcast_streams ssrc={}: {}",
500+
ss.get_ssrc(),
501+
err
502+
)));
498503
}
499504
};
500505
}
@@ -546,9 +551,14 @@ impl RTCDtlsTransport {
546551
}
547552
}
548553

549-
pub(crate) async fn store_simulcast_stream(&self, stream: Arc<Stream>) {
554+
pub(crate) async fn store_simulcast_stream(&self, ssrc: SSRC, stream: Arc<Stream>) {
555+
let mut simulcast_streams = self.simulcast_streams.lock().await;
556+
simulcast_streams.insert(ssrc, stream);
557+
}
558+
559+
pub(crate) async fn remove_simulcast_stream(&self, ssrc: SSRC) {
550560
let mut simulcast_streams = self.simulcast_streams.lock().await;
551-
simulcast_streams.push(stream)
561+
simulcast_streams.remove(&ssrc);
552562
}
553563

554564
pub(crate) async fn streams_for_ssrc(

src/peer_connection/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,15 +1857,15 @@ impl RTCPeerConnection {
18571857
let mut close_errs = vec![];
18581858

18591859
if let Err(err) = self.interceptor.close().await {
1860-
close_errs.push(err);
1860+
close_errs.push(Error::new(format!("interceptor: {}", err)));
18611861
}
18621862

18631863
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #4)
18641864
{
18651865
let mut rtp_transceivers = self.internal.rtp_transceivers.lock().await;
18661866
for t in &*rtp_transceivers {
18671867
if let Err(err) = t.stop().await {
1868-
close_errs.push(err.into());
1868+
close_errs.push(Error::new(format!("rtp_transceivers: {}", err)));
18691869
}
18701870
}
18711871
rtp_transceivers.clear();
@@ -1876,25 +1876,25 @@ impl RTCPeerConnection {
18761876
let mut data_channels = self.internal.sctp_transport.data_channels.lock().await;
18771877
for d in &*data_channels {
18781878
if let Err(err) = d.close().await {
1879-
close_errs.push(err.into());
1879+
close_errs.push(Error::new(format!("data_channels: {}", err)));
18801880
}
18811881
}
18821882
data_channels.clear();
18831883
}
18841884

18851885
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #6)
18861886
if let Err(err) = self.internal.sctp_transport.stop().await {
1887-
close_errs.push(err.into());
1887+
close_errs.push(Error::new(format!("sctp_transport: {}", err)));
18881888
}
18891889

18901890
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #7)
18911891
if let Err(err) = self.internal.dtls_transport.stop().await {
1892-
close_errs.push(err.into());
1892+
close_errs.push(Error::new(format!("dtls_transport: {}", err)));
18931893
}
18941894

18951895
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #8, #9, #10)
18961896
if let Err(err) = self.internal.ice_transport.stop().await {
1897-
close_errs.push(err.into());
1897+
close_errs.push(Error::new(format!("dtls_transport: {}", err)));
18981898
}
18991899

19001900
// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-close (step #11)
@@ -1908,7 +1908,7 @@ impl RTCPeerConnection {
19081908
.await;
19091909

19101910
if let Err(err) = self.internal.ops.close().await {
1911-
close_errs.push(err.into());
1911+
close_errs.push(Error::new(format!("ops: {}", err)));
19121912
}
19131913

19141914
flatten_errs(close_errs)

src/peer_connection/peer_connection_internal.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,12 @@ impl PeerConnectionInternal {
263263
let simulcast_routine_count2 = Arc::clone(&simulcast_routine_count);
264264
let pci2 = Arc::clone(&pci);
265265
tokio::spawn(async move {
266+
let ssrc = stream.get_ssrc();
267+
266268
dtls_transport2
267-
.store_simulcast_stream(Arc::clone(&stream))
269+
.store_simulcast_stream(ssrc, Arc::clone(&stream))
268270
.await;
269271

270-
let ssrc = stream.get_ssrc();
271272
if let Err(err) = pci2.handle_incoming_ssrc(stream, ssrc).await {
272273
log::error!(
273274
"Incoming unhandled RTP ssrc({}), on_track will not be fired. {}",
@@ -1182,6 +1183,7 @@ impl PeerConnectionInternal {
11821183
let _ = rtcp_read_stream.close().await;
11831184
}
11841185
icpr.unbind_remote_stream(&stream_info).await;
1186+
self.dtls_transport.remove_simulcast_stream(ssrc).await;
11851187
}
11861188

11871189
return Err(Error::ErrPeerConnSimulcastIncomingSSRCFailed);

0 commit comments

Comments
 (0)