Skip to content

Commit

Permalink
Add a=ice-options:trickle to session level of SDP as viewer (#1813)
Browse files Browse the repository at this point in the history
* Add a=ice-options:trickle to session level of SDP as viewer

* negative test case added

* clang format

* add chk_log_err to confirm what is null in the stack
  • Loading branch information
jdelapla authored and disa6302 committed Dec 5, 2023
1 parent 751bc91 commit 157fb64
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
1 change: 1 addition & 0 deletions samples/kvsWebRTCClientViewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ INT32 main(INT32 argc, CHAR* argv[])

MEMSET(&offerSessionDescriptionInit, 0x00, SIZEOF(RtcSessionDescriptionInit));

offerSessionDescriptionInit.useTrickleIce = pSampleStreamingSession->remoteCanTrickleIce;
CHK_STATUS(setLocalDescription(pSampleStreamingSession->pPeerConnection, &offerSessionDescriptionInit));
DLOGI("[KVS Viewer] Completed setting local description");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ typedef struct {
*/
typedef struct {
SDP_TYPE type; //!< Indicates an offer/answer SDP type
BOOL useTrickleIce; //!< Indicates if an offer should set trickle ice
CHAR sdp[MAX_SESSION_DESCRIPTION_INIT_SDP_LEN + 1]; //!< SDP Data containing media capabilities, transport addresses
//!< and related metadata in a transport agnostic manner
//!<
Expand Down
2 changes: 2 additions & 0 deletions src/source/Ice/IceUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ STATUS iceUtilsGenerateTransactionId(PBYTE pBuffer, UINT32 bufferLen)

CleanUp:

CHK_LOG_ERR(retStatus);

return retStatus;
}

Expand Down
3 changes: 3 additions & 0 deletions src/source/PeerConnection/PeerConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,9 @@ STATUS createOffer(PRtcPeerConnection pPeerConnection, PRtcSessionDescriptionIni
CHK(NULL != (pSessionDescription = (PSessionDescription) MEMCALLOC(1, SIZEOF(SessionDescription))), STATUS_NOT_ENOUGH_MEMORY);
pSessionDescriptionInit->type = SDP_TYPE_OFFER;
pKvsPeerConnection->isOffer = TRUE;
if (pSessionDescriptionInit->useTrickleIce) {
NULLABLE_SET_VALUE(pKvsPeerConnection->canTrickleIce, TRUE);
}

#ifdef ENABLE_DATA_CHANNEL
pKvsPeerConnection->sctpIsEnabled = TRUE;
Expand Down
8 changes: 7 additions & 1 deletion src/source/PeerConnection/SessionDescription.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,13 @@ STATUS populateSessionDescription(PKvsPeerConnection pKvsPeerConnection, PSessio

STRCPY(pLocalSessionDescription->sdpAttributes[0].attributeName, "group");
STRCPY(pLocalSessionDescription->sdpAttributes[0].attributeValue, BUNDLE_KEY);
pLocalSessionDescription->sessionAttributesCount++;

if (pKvsPeerConnection->canTrickleIce.value) {
STRCPY(pLocalSessionDescription->sdpAttributes[pLocalSessionDescription->sessionAttributesCount].attributeName, "ice-options");
STRCPY(pLocalSessionDescription->sdpAttributes[pLocalSessionDescription->sessionAttributesCount].attributeValue, "trickle");
pLocalSessionDescription->sessionAttributesCount++;
}

// check all session attribute lines to see if a line with BUNDLE is present. If it is present, copy its content and break
for (i = 0; i < pRemoteSessionDescription->sessionAttributesCount; i++) {
Expand Down Expand Up @@ -908,7 +915,6 @@ STATUS populateSessionDescription(PKvsPeerConnection pKvsPeerConnection, PSessio
STRCPY(pLocalSessionDescription->mediaDescriptions[i].sdpConnectionInformation.addressType, "IP4");
STRCPY(pLocalSessionDescription->mediaDescriptions[i].sdpConnectionInformation.connectionAddress, "127.0.0.1");
}
pLocalSessionDescription->sessionAttributesCount++;

STRCPY(pLocalSessionDescription->sdpAttributes[pLocalSessionDescription->sessionAttributesCount].attributeName, "msid-semantic");
STRCPY(pLocalSessionDescription->sdpAttributes[pLocalSessionDescription->sessionAttributesCount].attributeValue, " WMS myKvsVideoStream");
Expand Down
2 changes: 2 additions & 0 deletions src/source/Stun/Stun.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,8 @@ STATUS getStunAttribute(PStunPacket pStunPacket, STUN_ATTRIBUTE_TYPE attributeTy

CleanUp:

CHK_LOG_ERR(retStatus);

if (ppStunAttribute != NULL) {
*ppStunAttribute = pTargetAttribute;
}
Expand Down
62 changes: 61 additions & 1 deletion tst/SdpApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,66 @@ a=ice-options:trickle
});
}

TEST_F(SdpApiTest, noMediaTrickleIce) {
PRtcPeerConnection offerPc = NULL;
PRtcPeerConnection answerPc = NULL;
RtcConfiguration configurationOffer;
RtcConfiguration configurationAnswer;
RtcSessionDescriptionInit sessionDescriptionInitViewer;
RtcSessionDescriptionInit sessionDescriptionInitMaster;

MEMSET(&configurationOffer, 0x00, SIZEOF(RtcConfiguration));
MEMSET(&configurationAnswer, 0x00, SIZEOF(RtcConfiguration));

// Create peer connection
EXPECT_EQ(createPeerConnection(&configurationOffer, &offerPc), STATUS_SUCCESS);
EXPECT_EQ(createPeerConnection(&configurationAnswer, &answerPc), STATUS_SUCCESS);

sessionDescriptionInitViewer.useTrickleIce = TRUE;

EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sessionDescriptionInitViewer));
STRCPY(sessionDescriptionInitMaster.sdp, sessionDescriptionInitViewer.sdp);
sessionDescriptionInitMaster.type = SDP_TYPE_OFFER;
EXPECT_EQ(setRemoteDescription(answerPc, &sessionDescriptionInitMaster), STATUS_SUCCESS);
EXPECT_EQ(TRUE, canTrickleIceCandidates(answerPc).value);

closePeerConnection(offerPc);
freePeerConnection(&offerPc);

closePeerConnection(answerPc);
freePeerConnection(&answerPc);
}

TEST_F(SdpApiTest, noMediaTrickleIceNegativeCase) {
PRtcPeerConnection offerPc = NULL;
PRtcPeerConnection answerPc = NULL;
RtcConfiguration configurationOffer;
RtcConfiguration configurationAnswer;
RtcSessionDescriptionInit sessionDescriptionInitViewer;
RtcSessionDescriptionInit sessionDescriptionInitMaster;

MEMSET(&configurationOffer, 0x00, SIZEOF(RtcConfiguration));
MEMSET(&configurationAnswer, 0x00, SIZEOF(RtcConfiguration));

// Create peer connection
EXPECT_EQ(createPeerConnection(&configurationOffer, &offerPc), STATUS_SUCCESS);
EXPECT_EQ(createPeerConnection(&configurationAnswer, &answerPc), STATUS_SUCCESS);

sessionDescriptionInitViewer.useTrickleIce = FALSE;

EXPECT_EQ(STATUS_SUCCESS, createOffer(offerPc, &sessionDescriptionInitViewer));
STRCPY(sessionDescriptionInitMaster.sdp, sessionDescriptionInitViewer.sdp);
sessionDescriptionInitMaster.type = SDP_TYPE_OFFER;
EXPECT_EQ(setRemoteDescription(answerPc, &sessionDescriptionInitMaster), STATUS_SUCCESS);
EXPECT_EQ(FALSE, canTrickleIceCandidates(answerPc).value);

closePeerConnection(offerPc);
freePeerConnection(&offerPc);

closePeerConnection(answerPc);
freePeerConnection(&answerPc);
}

TEST_F(SdpApiTest, answerMlinesOrderSameAsOfferMLinesOrder)
{
auto offer = std::string(R"(v=0
Expand Down Expand Up @@ -2340,4 +2400,4 @@ INSTANTIATE_TEST_SUITE_P(SdpApiTest_SdpMatch_Safari, SdpApiTest_SdpMatch, ::test
} // namespace video
} // namespace kinesis
} // namespace amazonaws
} // namespace com
} // namespace com

0 comments on commit 157fb64

Please sign in to comment.