Skip to content

Commit 62f9bc8

Browse files
committed
Samples to demonstrate how to set a dual-stack custom control plane endpoint
1 parent 52df39f commit 62f9bc8

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

Diff for: samples/Common.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,13 @@ STATUS lookForSslCert(PSampleConfiguration* ppSampleConfiguration)
794794
return retStatus;
795795
}
796796

797-
STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE roleType, BOOL trickleIce, BOOL useTurn, UINT32 logLevel,
798-
PSampleConfiguration* ppSampleConfiguration)
797+
STATUS createSampleConfiguration(PCreateSampleConfigurationParams pCreateSampleConfigurationParams, PSampleConfiguration* ppSampleConfiguration)
799798
{
800799
STATUS retStatus = STATUS_SUCCESS;
801800
PCHAR pAccessKey, pSecretKey, pSessionToken;
802801
PSampleConfiguration pSampleConfiguration = NULL;
803802

804-
CHK(ppSampleConfiguration != NULL, STATUS_NULL_ARG);
803+
CHK(ppSampleConfiguration != NULL && pCreateSampleConfigurationParams != NULL, STATUS_NULL_ARG);
805804

806805
CHK(NULL != (pSampleConfiguration = (PSampleConfiguration) MEMCALLOC(1, SIZEOF(SampleConfiguration))), STATUS_NOT_ENOUGH_MEMORY);
807806

@@ -870,23 +869,39 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE
870869
pSampleConfiguration->signalingSendMessageLock = MUTEX_CREATE(FALSE);
871870
/* This is ignored for master. Master can extract the info from offer. Viewer has to know if peer can trickle or
872871
* not ahead of time. */
873-
pSampleConfiguration->trickleIce = trickleIce;
874-
pSampleConfiguration->useTurn = useTurn;
872+
pSampleConfiguration->trickleIce = pCreateSampleConfigurationParams->trickleIce;
873+
pSampleConfiguration->useTurn = pCreateSampleConfigurationParams->useTurn;
875874
pSampleConfiguration->enableSendingMetricsToViewerViaDc = FALSE;
876875
pSampleConfiguration->receiveAudioVideoSource = NULL;
877876

878877
pSampleConfiguration->channelInfo.version = CHANNEL_INFO_CURRENT_VERSION;
879-
pSampleConfiguration->channelInfo.pChannelName = channelName;
878+
pSampleConfiguration->channelInfo.pChannelName = pCreateSampleConfigurationParams->channelName;
880879
#ifdef IOT_CORE_ENABLE_CREDENTIALS
881880
if ((pIotCoreCertificateId = GETENV(IOT_CORE_CERTIFICATE_ID)) != NULL) {
882881
pSampleConfiguration->channelInfo.pChannelName = pIotCoreCertificateId;
883882
}
884883
#endif
884+
885+
if(pCreateSampleConfigurationParams->useDualStackEndpoints) {
886+
// Create the custom fully qualified control plane endpoint, sans the legacy/dual-stack postfix.
887+
SNPRINTF(pSampleConfiguration->customControlPlaneEndpoint, MAX_CONTROL_PLANE_URI_CHAR_LEN, "%s%s.%s", CONTROL_PLANE_URI_PREFIX, KINESIS_VIDEO_SERVICE_NAME, pSampleConfiguration->channelInfo.pRegion);
888+
889+
if (STRSTR(pSampleConfiguration->channelInfo.pRegion, "cn-")) {
890+
STRCAT(pSampleConfiguration->customControlPlaneEndpoint, CONTROL_PLANE_URI_POSTFIX_CN_DUAL_STACK); // Will use CN region dual-stack endpoint.
891+
} else {
892+
STRCAT(pSampleConfiguration->customControlPlaneEndpoint, CONTROL_PLANE_URI_POSTFIX_DUAL_STACK); // Will use Dual-stack endpoint.
893+
}
894+
895+
pSampleConfiguration->channelInfo.pControlPlaneUrl = pSampleConfiguration->customControlPlaneEndpoint;
896+
} else {
897+
pSampleConfiguration->channelInfo.pControlPlaneUrl = NULL; // Will use default legacy endpoints.
898+
}
899+
885900
pSampleConfiguration->channelInfo.pKmsKeyId = NULL;
886901
pSampleConfiguration->channelInfo.tagCount = 0;
887902
pSampleConfiguration->channelInfo.pTags = NULL;
888903
pSampleConfiguration->channelInfo.channelType = SIGNALING_CHANNEL_TYPE_SINGLE_MASTER;
889-
pSampleConfiguration->channelInfo.channelRoleType = roleType;
904+
pSampleConfiguration->channelInfo.channelRoleType = pCreateSampleConfigurationParams->roleType;
890905
pSampleConfiguration->channelInfo.cachingPolicy = SIGNALING_API_CALL_CACHE_TYPE_FILE;
891906
pSampleConfiguration->channelInfo.cachingPeriod = SIGNALING_API_CALL_CACHE_TTL_SENTINEL_VALUE;
892907
pSampleConfiguration->channelInfo.asyncIceServerConfig = TRUE; // has no effect
@@ -901,7 +916,7 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE
901916
pSampleConfiguration->signalingClientCallbacks.customData = (UINT64) pSampleConfiguration;
902917

903918
pSampleConfiguration->clientInfo.version = SIGNALING_CLIENT_INFO_CURRENT_VERSION;
904-
pSampleConfiguration->clientInfo.loggingLevel = logLevel;
919+
pSampleConfiguration->clientInfo.loggingLevel = pCreateSampleConfigurationParams->logLevel;
905920
pSampleConfiguration->clientInfo.cacheFilePath = NULL; // Use the default path
906921
pSampleConfiguration->clientInfo.signalingClientCreationMaxRetryAttempts = CREATE_SIGNALING_CLIENT_RETRY_ATTEMPTS_SENTINEL_VALUE;
907922
pSampleConfiguration->iceCandidatePairStatsTimerId = MAX_UINT32;

Diff for: samples/Samples.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ typedef struct {
115115
UINT64 prevTs;
116116
} RtcMetricsHistory, *PRtcMetricsHistory;
117117

118+
typedef struct {
119+
PCHAR channelName;
120+
SIGNALING_CHANNEL_ROLE_TYPE roleType;
121+
BOOL trickleIce;
122+
BOOL useTurn;
123+
BOOL useDualStackEndpoints;
124+
UINT32 logLevel;
125+
} CreateSampleConfigurationParams, *PCreateSampleConfigurationParams;
126+
118127
typedef struct {
119128
volatile ATOMIC_BOOL appTerminateFlag;
120129
volatile ATOMIC_BOOL interrupted;
@@ -176,6 +185,8 @@ typedef struct {
176185
UINT32 logLevel;
177186
BOOL enableTwcc;
178187
BOOL enableIceStats;
188+
BOOL useDualStackEndpoints;
189+
CHAR customControlPlaneEndpoint[MAX_CONTROL_PLANE_URI_CHAR_LEN];
179190
} SampleConfiguration, *PSampleConfiguration;
180191

181192
typedef struct {
@@ -247,7 +258,7 @@ PVOID sampleReceiveAudioVideoFrame(PVOID);
247258
PVOID getPeriodicIceCandidatePairStats(PVOID);
248259
STATUS getIceCandidatePairStatsCallback(UINT32, UINT64, UINT64);
249260
STATUS pregenerateCertTimerCallback(UINT32, UINT64, UINT64);
250-
STATUS createSampleConfiguration(PCHAR, SIGNALING_CHANNEL_ROLE_TYPE, BOOL, BOOL, UINT32, PSampleConfiguration*);
261+
STATUS createSampleConfiguration(PCreateSampleConfigurationParams, PSampleConfiguration*);
251262
STATUS freeSampleConfiguration(PSampleConfiguration*);
252263
STATUS signalingClientStateChanged(UINT64, SIGNALING_CLIENT_STATE);
253264
STATUS signalingMessageReceived(UINT64, PReceivedSignalingMessage);

Diff for: samples/kvsWebRTCClientMaster.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ INT32 main(INT32 argc, CHAR* argv[])
1212
signalingClientMetrics.version = SIGNALING_CLIENT_METRICS_CURRENT_VERSION;
1313
RTC_CODEC audioCodec = RTC_CODEC_OPUS;
1414
RTC_CODEC videoCodec = RTC_CODEC_H264_PROFILE_42E01F_LEVEL_ASYMMETRY_ALLOWED_PACKETIZATION_MODE;
15+
CreateSampleConfigurationParams createSampleConfigurationParams;
1516

1617
SET_INSTRUMENTED_ALLOCATORS();
1718
UINT32 logLevel = setLogLevel();
@@ -27,8 +28,15 @@ INT32 main(INT32 argc, CHAR* argv[])
2728
pChannelName = argc > 1 ? argv[1] : SAMPLE_CHANNEL_NAME;
2829
#endif
2930

30-
CHK_STATUS(createSampleConfiguration(pChannelName, SIGNALING_CHANNEL_ROLE_TYPE_MASTER, TRUE, TRUE, logLevel, &pSampleConfiguration));
31+
createSampleConfigurationParams.channelName = pChannelName;
32+
createSampleConfigurationParams.roleType = SIGNALING_CHANNEL_ROLE_TYPE_MASTER;
33+
createSampleConfigurationParams.trickleIce = TRUE;
34+
createSampleConfigurationParams.useTurn = TRUE;
35+
createSampleConfigurationParams.useDualStackEndpoints = FALSE;
36+
createSampleConfigurationParams.logLevel = logLevel;
3137

38+
CHK_STATUS(createSampleConfiguration(&createSampleConfigurationParams, &pSampleConfiguration));
39+
3240
if (argc > 3) {
3341
if (!STRCMP(argv[3], AUDIO_CODEC_NAME_OPUS)) {
3442
audioCodec = RTC_CODEC_OPUS;

Diff for: src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h

+5
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ extern "C" {
460460
*/
461461
#define MAX_SIGNALING_ENDPOINT_URI_LEN 512
462462

463+
/**
464+
* Maximum allowed Control Plane URI length
465+
*/
466+
#define MAX_CONTROL_PLANE_URI_CHAR_LEN 256
467+
463468
/**
464469
* Maximum allowed correlation ID length
465470
*/

Diff for: src/source/Signaling/ChannelInfo.h

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ Signaling internal include file
1010
extern "C" {
1111
#endif
1212

13-
// Max control plane URI char len
14-
#define MAX_CONTROL_PLANE_URI_CHAR_LEN 256
15-
1613
// Max channel status string length in describe API call in chars
1714
#define MAX_DESCRIBE_CHANNEL_STATUS_LEN 32
1815

0 commit comments

Comments
 (0)