@@ -60,27 +60,43 @@ TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersWithDelay)
60
60
RtcSessionDescriptionInit sdp;
61
61
SIZE_T connectedCount = 0 ;
62
62
PRtcPeerConnection offerPc = NULL , answerPc = NULL ;
63
+ PeerContainer offer;
64
+ PeerContainer answer;
63
65
64
66
MEMSET (&configuration, 0x00 , SIZEOF (RtcConfiguration));
65
67
66
68
EXPECT_EQ (createPeerConnection (&configuration, &offerPc), STATUS_SUCCESS);
67
69
EXPECT_EQ (createPeerConnection (&configuration, &answerPc), STATUS_SUCCESS);
68
70
69
71
auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void {
72
+ PPeerContainer container = (PPeerContainer)customData;
70
73
if (candidateStr != NULL ) {
71
- std::thread (
72
- [customData](std::string candidate) {
73
- RtcIceCandidateInit iceCandidate;
74
- EXPECT_EQ (STATUS_SUCCESS, deserializeRtcIceCandidateInit ((PCHAR) candidate.c_str (), STRLEN (candidate.c_str ()), &iceCandidate));
75
- EXPECT_EQ (STATUS_SUCCESS, addIceCandidate ((PRtcPeerConnection) customData, iceCandidate.candidate ));
76
- },
77
- std::string (candidateStr))
78
- .detach ();
74
+ container->client ->lock .lock ();
75
+ if (!container->client ->noNewThreads ) {
76
+ container->client ->threads .push_back (std::thread (
77
+ [container](std::string candidate) {
78
+ RtcIceCandidateInit iceCandidate;
79
+ EXPECT_EQ (STATUS_SUCCESS, deserializeRtcIceCandidateInit ((PCHAR) candidate.c_str (), STRLEN (candidate.c_str ()), &iceCandidate));
80
+ EXPECT_EQ (STATUS_SUCCESS, addIceCandidate ((PRtcPeerConnection) container->pc , iceCandidate.candidate ));
81
+ },
82
+ std::string (candidateStr)));
83
+ }
84
+ container->client ->lock .unlock ();
79
85
}
80
86
};
81
87
82
- EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) answerPc, onICECandidateHdlr));
83
- EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) offerPc, onICECandidateHdlr));
88
+ offer.pc = offerPc;
89
+ offer.client = this ;
90
+ answer.pc = answerPc;
91
+ answer.client = this ;
92
+
93
+ auto onICECandidateHdlrDone = [](UINT64 customData, PCHAR candidateStr) -> void {
94
+ UNUSED_PARAM (customData);
95
+ UNUSED_PARAM (candidateStr);
96
+ };
97
+
98
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) &answer, onICECandidateHdlr));
99
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) &offer, onICECandidateHdlr));
84
100
85
101
auto onICEConnectionStateChangeHdlr = [](UINT64 customData, RTC_PEER_CONNECTION_STATE newState) -> void {
86
102
if (newState == RTC_PEER_CONNECTION_STATE_CONNECTED) {
@@ -108,6 +124,17 @@ TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersWithDelay)
108
124
109
125
EXPECT_EQ (2 , connectedCount);
110
126
127
+ this ->lock .lock ();
128
+ // join all threads before leaving
129
+ for (auto & th : this ->threads ) th.join ();
130
+
131
+ this ->threads .clear ();
132
+ this ->noNewThreads = TRUE ;
133
+ this ->lock .unlock ();
134
+
135
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) 0 , onICECandidateHdlrDone));
136
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) 0 , onICECandidateHdlrDone));
137
+
111
138
closePeerConnection (offerPc);
112
139
closePeerConnection (answerPc);
113
140
@@ -635,6 +662,9 @@ TEST_F(PeerConnectionFunctionalityTest, noLostFramesAfterConnected)
635
662
ATOMIC_BOOL seenFirstFrame = FALSE ;
636
663
Frame videoFrame;
637
664
665
+ PeerContainer offer;
666
+ PeerContainer answer;
667
+
638
668
MEMSET (&configuration, 0x00 , SIZEOF (RtcConfiguration));
639
669
MEMSET (&videoFrame, 0x00 , SIZEOF (Frame));
640
670
@@ -654,6 +684,33 @@ TEST_F(PeerConnectionFunctionalityTest, noLostFramesAfterConnected)
654
684
addTrackToPeerConnection (offerPc, &offerVideoTrack, &offerVideoTransceiver, RTC_CODEC_VP8, MEDIA_STREAM_TRACK_KIND_VIDEO);
655
685
addTrackToPeerConnection (answerPc, &answerVideoTrack, &answerVideoTransceiver, RTC_CODEC_VP8, MEDIA_STREAM_TRACK_KIND_VIDEO);
656
686
687
+ auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void {
688
+ PPeerContainer container = (PPeerContainer)customData;
689
+ if (candidateStr != NULL ) {
690
+ container->client ->lock .lock ();
691
+ if (!container->client ->noNewThreads ) {
692
+ container->client ->threads .push_back (std::thread (
693
+ [container](std::string candidate) {
694
+ RtcIceCandidateInit iceCandidate;
695
+ EXPECT_EQ (STATUS_SUCCESS, deserializeRtcIceCandidateInit ((PCHAR) candidate.c_str (), STRLEN (candidate.c_str ()), &iceCandidate));
696
+ EXPECT_EQ (STATUS_SUCCESS, addIceCandidate ((PRtcPeerConnection) container->pc , iceCandidate.candidate ));
697
+ },
698
+ std::string (candidateStr)));
699
+ }
700
+ container->client ->lock .unlock ();
701
+ }
702
+ };
703
+
704
+ offer.pc = offerPc;
705
+ offer.client = this ;
706
+ answer.pc = answerPc;
707
+ answer.client = this ;
708
+
709
+ auto onICECandidateHdlrDone = [](UINT64 customData, PCHAR candidateStr) -> void {
710
+ UNUSED_PARAM (customData);
711
+ UNUSED_PARAM (candidateStr);
712
+ };
713
+
657
714
auto onFrameHandler = [](UINT64 customData, PFrame pFrame) -> void {
658
715
UNUSED_PARAM (pFrame);
659
716
if (pFrame->frameData [0 ] == 1 ) {
@@ -662,21 +719,8 @@ TEST_F(PeerConnectionFunctionalityTest, noLostFramesAfterConnected)
662
719
};
663
720
EXPECT_EQ (transceiverOnFrame (answerVideoTransceiver, (UINT64) &seenFirstFrame, onFrameHandler), STATUS_SUCCESS);
664
721
665
- auto onICECandidateHdlr = [](UINT64 customData, PCHAR candidateStr) -> void {
666
- if (candidateStr != NULL ) {
667
- std::thread (
668
- [customData](std::string candidate) {
669
- RtcIceCandidateInit iceCandidate;
670
- EXPECT_EQ (STATUS_SUCCESS, deserializeRtcIceCandidateInit ((PCHAR) candidate.c_str (), STRLEN (candidate.c_str ()), &iceCandidate));
671
- EXPECT_EQ (STATUS_SUCCESS, addIceCandidate ((PRtcPeerConnection) customData, iceCandidate.candidate ));
672
- },
673
- std::string (candidateStr))
674
- .detach ();
675
- }
676
- };
677
-
678
- EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) answerPc, onICECandidateHdlr));
679
- EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) offerPc, onICECandidateHdlr));
722
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) &answer, onICECandidateHdlr));
723
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) &offer, onICECandidateHdlr));
680
724
681
725
auto onICEConnectionStateChangeHdlr = [](UINT64 customData, RTC_PEER_CONNECTION_STATE newState) -> void {
682
726
Context* pContext = (Context*) customData;
@@ -714,6 +758,16 @@ TEST_F(PeerConnectionFunctionalityTest, noLostFramesAfterConnected)
714
758
THREAD_SLEEP (HUNDREDS_OF_NANOS_IN_A_MILLISECOND);
715
759
}
716
760
761
+ this ->lock .lock ();
762
+ for (auto & th : this ->threads ) th.join ();
763
+
764
+ this ->threads .clear ();
765
+ this ->noNewThreads = TRUE ;
766
+ this ->lock .unlock ();
767
+
768
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (offerPc, (UINT64) 0 , onICECandidateHdlrDone));
769
+ EXPECT_EQ (STATUS_SUCCESS, peerConnectionOnIceCandidate (answerPc, (UINT64) 0 , onICECandidateHdlrDone));
770
+
717
771
MEMFREE (videoFrame.frameData );
718
772
closePeerConnection (offerPc);
719
773
closePeerConnection (answerPc);
0 commit comments