From 7586eb2fe1e676a5ea8224fd1122a4857b4fbae2 Mon Sep 17 00:00:00 2001 From: "Alex.D.Scofield" Date: Fri, 20 Jan 2023 19:10:23 +0000 Subject: [PATCH] add support for CN region (#1612) Signed-off-by: Alex Li Signed-off-by: Alex Li --- samples/Common.c | 8 +++++++- .../com/amazonaws/kinesis/video/webrtcclient/Include.h | 4 +++- src/source/Signaling/ChannelInfo.c | 4 ++++ tst/PeerConnectionFunctionalityTest.cpp | 4 ++-- tst/SdpApiTest.cpp | 8 ++++---- tst/WebRTCClientTestFixture.cpp | 2 +- tst/WebRTCClientTestFixture.h | 1 + 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 76862d1bff..6172272e04 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -377,7 +377,13 @@ STATUS initializePeerConnection(PSampleConfiguration pSampleConfiguration, PRtcP configuration.iceTransportPolicy = ICE_TRANSPORT_POLICY_ALL; // Set the STUN server - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion); + PCHAR pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX; + // If region is in CN, add CN region uri postfix + if (STRSTR(pSampleConfiguration->channelInfo.pRegion, "cn-")) { + pKinesisVideoStunUrlPostFix = KINESIS_VIDEO_STUN_URL_POSTFIX_CN; + } + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, pSampleConfiguration->channelInfo.pRegion, + pKinesisVideoStunUrlPostFix); if (pSampleConfiguration->useTurn) { // Set the URIs from the configuration diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 943a355236..973b59984d 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -670,7 +670,9 @@ extern "C" { /** * Parameterized string for KVS STUN Server */ -#define KINESIS_VIDEO_STUN_URL "stun:stun.kinesisvideo.%s.amazonaws.com:443" +#define KINESIS_VIDEO_STUN_URL_POSTFIX "amazonaws.com" +#define KINESIS_VIDEO_STUN_URL_POSTFIX_CN "amazonaws.com.cn" +#define KINESIS_VIDEO_STUN_URL "stun:stun.kinesisvideo.%s.%s:443" /** * Default signaling SSL port diff --git a/src/source/Signaling/ChannelInfo.c b/src/source/Signaling/ChannelInfo.c index 17cf3e4bfe..6f8dcaf560 100644 --- a/src/source/Signaling/ChannelInfo.c +++ b/src/source/Signaling/ChannelInfo.c @@ -138,6 +138,10 @@ STATUS createValidateChannelInfo(PChannelInfo pOrigChannelInfo, PChannelInfo* pp // Create a fully qualified URI SNPRINTF(pCurPtr, MAX_CONTROL_PLANE_URI_CHAR_LEN, "%s%s.%s%s", CONTROL_PLANE_URI_PREFIX, KINESIS_VIDEO_SERVICE_NAME, pChannelInfo->pRegion, CONTROL_PLANE_URI_POSTFIX); + // If region is in CN, add CN region uri postfix + if (STRSTR(pChannelInfo->pRegion, "cn-")) { + STRCAT(pCurPtr, ".cn"); + } } pChannelInfo->pControlPlaneUrl = pCurPtr; diff --git a/tst/PeerConnectionFunctionalityTest.cpp b/tst/PeerConnectionFunctionalityTest.cpp index 955d0a25af..5a5e3ed3d5 100644 --- a/tst/PeerConnectionFunctionalityTest.cpp +++ b/tst/PeerConnectionFunctionalityTest.cpp @@ -232,7 +232,7 @@ TEST_F(PeerConnectionFunctionalityTest, sendDataWithClosedSocketConnectionWithHo PSocketConnection pSocketConnection; MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); @@ -524,7 +524,7 @@ TEST_F(PeerConnectionFunctionalityTest, connectTwoPeersWithHostAndStun) MEMSET(&configuration, 0x00, SIZEOF(RtcConfiguration)); // Set the STUN server - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); EXPECT_EQ(createPeerConnection(&configuration, &offerPc), STATUS_SUCCESS); EXPECT_EQ(createPeerConnection(&configuration, &answerPc), STATUS_SUCCESS); diff --git a/tst/SdpApiTest.cpp b/tst/SdpApiTest.cpp index f1e651f2dd..ccc0fa4599 100644 --- a/tst/SdpApiTest.cpp +++ b/tst/SdpApiTest.cpp @@ -614,7 +614,7 @@ a=group:BUNDLE 0 RtcSessionDescriptionInit offerSdp{}; RtcSessionDescriptionInit answerSdp{}; - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); track1.kind = MEDIA_STREAM_TRACK_KIND_VIDEO; track1.codec = RTC_CODEC_VP8; @@ -728,7 +728,7 @@ a=group:BUNDLE 0 RtcSessionDescriptionInit offerSdp{}; RtcSessionDescriptionInit answerSdp{}; - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); track1.kind = MEDIA_STREAM_TRACK_KIND_VIDEO; track1.codec = RTC_CODEC_VP8; @@ -786,7 +786,7 @@ a=group:BUNDLE 0 RtcSessionDescriptionInit offerSdp{}; RtcSessionDescriptionInit answerSdp{}; - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); track1.kind = MEDIA_STREAM_TRACK_KIND_VIDEO; track1.codec = RTC_CODEC_VP8; @@ -849,7 +849,7 @@ a=ice-options:trickle RtcSessionDescriptionInit offerSdp{}; RtcSessionDescriptionInit answerSdp{}; - SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(configuration.iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); track1.kind = MEDIA_STREAM_TRACK_KIND_VIDEO; track1.codec = RTC_CODEC_VP8; diff --git a/tst/WebRTCClientTestFixture.cpp b/tst/WebRTCClientTestFixture.cpp index 8291bcf6de..d041db728e 100644 --- a/tst/WebRTCClientTestFixture.cpp +++ b/tst/WebRTCClientTestFixture.cpp @@ -256,7 +256,7 @@ void WebRtcClientTestBase::getIceServers(PRtcConfiguration pRtcConfiguration) EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfoCount(mSignalingClientHandle, &iceConfigCount)); // Set the STUN server - SNPRINTF(pRtcConfiguration->iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION); + SNPRINTF(pRtcConfiguration->iceServers[0].urls, MAX_ICE_CONFIG_URI_LEN, KINESIS_VIDEO_STUN_URL, TEST_DEFAULT_REGION, TEST_DEFAULT_STUN_URL_POSTFIX); for (uriCount = 0, i = 0; i < iceConfigCount; i++) { EXPECT_EQ(STATUS_SUCCESS, signalingClientGetIceConfigInfo(mSignalingClientHandle, i, &pIceConfigInfo)); diff --git a/tst/WebRTCClientTestFixture.h b/tst/WebRTCClientTestFixture.h index 28a0686521..f4abf4532e 100644 --- a/tst/WebRTCClientTestFixture.h +++ b/tst/WebRTCClientTestFixture.h @@ -8,6 +8,7 @@ #include #define TEST_DEFAULT_REGION ((PCHAR) "us-west-2") +#define TEST_DEFAULT_STUN_URL_POSTFIX (KINESIS_VIDEO_STUN_URL_POSTFIX) #define TEST_STREAMING_TOKEN_DURATION (40 * HUNDREDS_OF_NANOS_IN_A_SECOND) #define TEST_JITTER_BUFFER_CLOCK_RATE (1000) #define TEST_SIGNALING_MASTER_CLIENT_ID (PCHAR) "Test_Master_ClientId"