From 0ac685130293fc12382b9a8ea0cde75e8f6b3b52 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 16 Oct 2023 15:34:25 -0700 Subject: [PATCH 01/51] data channel benchmarking message --- samples/Common.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-- samples/Samples.h | 11 ++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 0ec5ee5439..ab07e3d669 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -33,15 +33,79 @@ STATUS signalingCallFailed(STATUS status) VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen) { + STATUS retStatus = STATUS_SUCCESS; + UINT32 i, strLen, tokenCount; + UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, t1, t2, t3, t4, t5; + DataChannelMessage dataChannelMessage = { '\0', '\0', '\0', '\0', '\0', '\0' }; + CHAR pMessageSend[SIZEOF(DataChannelMessage)]; + jsmn_parser parser; + jsmn_init(&parser); + jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; + + PCHAR json = (PCHAR) pMessage; + + tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); + + for (i = 1; i < tokenCount; i++) { + if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t1")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t2")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t2, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t3[0] = '\0'; + dataChannelMessage.t4[0] = '\0'; + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t3")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t4")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t4, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t5")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } + } + UNUSED_PARAM(customData); if (isBinary) { DLOGI("DataChannel Binary Message"); } else { DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); } - // Send a response to the message sent by the viewer - STATUS retStatus = STATUS_SUCCESS; - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + + if (STRLEN(dataChannelMessage.t5) == 0) { + SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, + dataChannelMessage.t1, dataChannelMessage.t2, dataChannelMessage.t3, + dataChannelMessage.t4, dataChannelMessage.t5); + DLOGI("Master's response: %s", pMessageSend); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); + } else { + STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); + STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); + STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); + masterToViewerE2E = t3 - t2; + viewerToMasterE2E = t4 - t3; + DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); + DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + } + if (retStatus != STATUS_SUCCESS) { DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); } diff --git a/samples/Samples.h b/samples/Samples.h index 1bb705b800..acf12884c1 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -51,6 +51,7 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" +#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" /* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ // #define IOT_CORE_ENABLE_CREDENTIALS 1 @@ -131,6 +132,16 @@ typedef struct { UINT32 logLevel; } SampleConfiguration, *PSampleConfiguration; +typedef struct { + CHAR content[100]; + CHAR t1[100]; + CHAR t2[100]; + CHAR t3[100]; + CHAR t4[100]; + CHAR t5[100]; +} DataChannelMessage; + + typedef struct { UINT64 hashValue; UINT64 createTime; From f2e83e1de64d273e849efeb95cf2099c1d92f1d4 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 18 Oct 2023 15:02:54 -0700 Subject: [PATCH 02/51] fix calculation --- samples/Common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index ab07e3d669..d0a076a2e2 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -97,11 +97,12 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { + STRTOUI64(dataChannelMessage.t1, dataChannelMessage.t1 + STRLEN(dataChannelMessage.t2), 10, &t1); STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); - masterToViewerE2E = t3 - t2; - viewerToMasterE2E = t4 - t3; + masterToViewerE2E = t3 - t1; + viewerToMasterE2E = t4 - t2; DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); } From 42e641af0b5dd5ca89ae714a2af0ff9e0d3bb13e Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 30 Oct 2023 15:49:11 -0700 Subject: [PATCH 03/51] send peerconnection, iceagent, signaling metrics to viewer via dc --- samples/Common.c | 36 ++++++++++++++++++++++++++++++++++++ samples/Samples.h | 15 +++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index d0a076a2e2..e0738a777f 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -105,6 +105,9 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL viewerToMasterE2E = t4 - t2; DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); } if (retStatus != STATUS_SUCCESS) { @@ -132,8 +135,41 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); + SNPRINTF(pSignalingClientMetricsMessage, STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 13, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.cpApiCallLatency, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.dpApiCallLatency, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getEndpointCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceConfigCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.fetchClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + DLOGI("SIGNALING_METRICS: %s", pSignalingClientMetricsMessage); + + CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); + SNPRINTF(pPeerConnectionMetricsMessage, STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 3, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionCreationTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.dtlsSessionSetupTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.iceHolePunchingTime); + DLOGI("PEER_CONNECTION_METRICS: %s", pPeerConnectionMetricsMessage); + + CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); + SNPRINTF(pIceAgentMetricsMessage, STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 8, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.localCandidateGatheringTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.hostCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.srflxCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.relayCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceServerParsingTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceCandidatePairNominationTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceAgentSetUpTime); + DLOGI("ICE_CONNECTION_METRICS: %s", pIceAgentMetricsMessage); if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { DLOGW("Failed to get information about selected Ice candidates: 0x%08x", retStatus); diff --git a/samples/Samples.h b/samples/Samples.h index acf12884c1..a612ee0f30 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -49,12 +49,23 @@ extern "C" { #define IOT_CORE_THING_NAME ((PCHAR) "AWS_IOT_CORE_THING_NAME") #define IOT_CORE_CERTIFICATE_ID ((PCHAR) "AWS_IOT_CORE_CERTIFICATE_ID") +/* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ +// #define IOT_CORE_ENABLE_CREDENTIALS 1 + #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" #define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" +#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionCreationTime\":\"%llu\", \"dtlsSessionSetupTime\":\"%llu\", \"iceHolePunchingTime\":\"%llu\"}" +#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"cpApiCallLatency\":\"%llu\", \"dpApiCallLatency\":\"%llu\", \"getTokenCallTime\":\"%llu\", \"describeCallTime\":\"%llu\", \"createCallTime\":\"%llu\", \"getEndpointCallTime\":\"%llu\", \"getIceConfigCallTime\":\"%llu\", \"connectCallTime\":\"%llu\", \"createClientTime\":\"%llu\", \"fetchClientTime\":\"%llu\", \"connectClientTime\":\"%llu\", \"offerToAnswerTime\":\"%llu\"}" +#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"localCandidateGatheringTime\":\"%llu\", \"hostCandidateSetUpTime\":\"%llu\", \"srflxCandidateSetUpTime\":\"%llu\", \"relayCandidateSetUpTime\":\"%llu\", \"iceServerParsingTime\":\"%llu\", \"iceCandidatePairNominationTime\":\"%llu\", \"candidateGatheringTime\":\"%llu\", \"iceAgentSetUpTime\":\"%llu\"}" -/* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ -// #define IOT_CORE_ENABLE_CREDENTIALS 1 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 3 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 329 + 20 * 13 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 8 + +CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; +CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; +CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; typedef enum { SAMPLE_STREAMING_VIDEO_ONLY, From 049cc1734981dd694c84ca727e4844329f079f09 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 8 Nov 2023 20:43:27 -0800 Subject: [PATCH 04/51] signaling breakdown --- samples/Common.c | 64 +++++++++++-------- samples/Samples.h | 24 +++---- samples/kvsWebRTCClientMaster.c | 2 + .../kinesis/video/webrtcclient/Include.h | 8 +++ .../kinesis/video/webrtcclient/Stats.h | 20 ++++++ src/source/Ice/IceAgent.c | 3 + src/source/Ice/IceAgent.h | 1 + src/source/Signaling/Signaling.c | 12 ++++ src/source/Signaling/Signaling.h | 22 +++++-- src/source/Signaling/StateMachine.c | 24 +++---- 10 files changed, 125 insertions(+), 55 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index e0738a777f..10db5f2f51 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -101,10 +101,13 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); + masterToViewerE2E = t3 - t1; viewerToMasterE2E = t4 - t2; + DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); @@ -135,40 +138,39 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); - SNPRINTF(pSignalingClientMetricsMessage, STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 13, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.cpApiCallLatency, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.dpApiCallLatency, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getEndpointCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceConfigCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.fetchClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME(); + SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + DLOGI("SIGNALING_METRICS: %s", pSignalingClientMetricsMessage); CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 3, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionCreationTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.dtlsSessionSetupTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.iceHolePunchingTime); + SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); DLOGI("PEER_CONNECTION_METRICS: %s", pPeerConnectionMetricsMessage); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 8, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.localCandidateGatheringTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.hostCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.srflxCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.relayCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceServerParsingTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceCandidatePairNominationTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceAgentSetUpTime); + SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); DLOGI("ICE_CONNECTION_METRICS: %s", pIceAgentMetricsMessage); if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { @@ -373,7 +375,7 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi locked = TRUE; CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); + // CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); } @@ -608,6 +610,7 @@ STATUS createSampleStreamingSession(PSampleConfiguration pSampleConfiguration, P ATOMIC_STORE_BOOL(&pSampleStreamingSession->terminateFlag, FALSE); ATOMIC_STORE_BOOL(&pSampleStreamingSession->candidateGatheringDone, FALSE); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime = GETTIME(); CHK_STATUS(initializePeerConnection(pSampleConfiguration, &pSampleStreamingSession->pPeerConnection)); CHK_STATUS(peerConnectionOnIceCandidate(pSampleStreamingSession->pPeerConnection, (UINT64) pSampleStreamingSession, onIceCandidateHandler)); CHK_STATUS( @@ -985,6 +988,8 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) STATUS retStatus = STATUS_SUCCESS; SignalingClientMetrics signalingClientMetrics = pSampleConfiguration->signalingClientMetrics; pSampleConfiguration->signalingClientCallbacks.messageReceivedFn = signalingMessageReceived; + UINT64 startTime = GETTIME(); + STRCPY(pSampleConfiguration->clientInfo.clientId, clientId); CHK_STATUS(createSignalingClientSync(&pSampleConfiguration->clientInfo, &pSampleConfiguration->channelInfo, &pSampleConfiguration->signalingClientCallbacks, pSampleConfiguration->pCredentialProvider, @@ -1007,6 +1012,7 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); pSampleConfiguration->signalingClientMetrics = signalingClientMetrics; + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = startTime; gSampleConfiguration = pSampleConfiguration; CleanUp: return retStatus; @@ -1461,6 +1467,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe switch (pReceivedSignalingMessage->signalingMessage.messageType) { case SIGNALING_MESSAGE_TYPE_OFFER: + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime = GETTIME(); // Check if we already have an ongoing master session with the same peer CHK_ERR(!peerConnectionFound, STATUS_INVALID_OPERATION, "Peer connection %s is in progress", pReceivedSignalingMessage->signalingMessage.peerClientId); @@ -1490,6 +1497,9 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock); CHK_STATUS(handleOffer(pSampleConfiguration, pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage)); + + pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime = GETTIME(); + CHK_STATUS(hashTablePut(pSampleConfiguration->pRtcPeerConnectionForRemoteClient, clientIdHash, (UINT64) pSampleStreamingSession)); // If there are any ice candidate messages in the queue for this client id, submit them now. diff --git a/samples/Samples.h b/samples/Samples.h index a612ee0f30..9fbd64b79c 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -54,14 +54,14 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" -#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" -#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionCreationTime\":\"%llu\", \"dtlsSessionSetupTime\":\"%llu\", \"iceHolePunchingTime\":\"%llu\"}" -#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"cpApiCallLatency\":\"%llu\", \"dpApiCallLatency\":\"%llu\", \"getTokenCallTime\":\"%llu\", \"describeCallTime\":\"%llu\", \"createCallTime\":\"%llu\", \"getEndpointCallTime\":\"%llu\", \"getIceConfigCallTime\":\"%llu\", \"connectCallTime\":\"%llu\", \"createClientTime\":\"%llu\", \"fetchClientTime\":\"%llu\", \"connectClientTime\":\"%llu\", \"offerToAnswerTime\":\"%llu\"}" -#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"localCandidateGatheringTime\":\"%llu\", \"hostCandidateSetUpTime\":\"%llu\", \"srflxCandidateSetUpTime\":\"%llu\", \"relayCandidateSetUpTime\":\"%llu\", \"iceServerParsingTime\":\"%llu\", \"iceCandidatePairNominationTime\":\"%llu\", \"candidateGatheringTime\":\"%llu\", \"iceAgentSetUpTime\":\"%llu\"}" +#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" +#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" +#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, \"describeChannelStartTime\": %llu, \"describeChannelEndTime\": %llu, \"getSignalingChannelEndpointStartTime\": %llu, \"getSignalingChannelEndpointEndTime\": %llu, \"getIceServerConfigStartTime\": %llu, \"getIceServerConfigEndTime\": %llu, \"getTokenStartTime\": %llu, \"getTokenEndTime\": %llu, \"createChannelStartTime\": %llu, \"createChannelEndTime\": %llu, \"connectStartTime\": %llu, \"connectEndTime\": %llu }" +#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 3 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 329 + 20 * 13 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 8 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 2 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 497 + 20 * 10 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; @@ -145,11 +145,11 @@ typedef struct { typedef struct { CHAR content[100]; - CHAR t1[100]; - CHAR t2[100]; - CHAR t3[100]; - CHAR t4[100]; - CHAR t5[100]; + CHAR t1[20]; + CHAR t2[20]; + CHAR t3[20]; + CHAR t4[20]; + CHAR t5[20]; } DataChannelMessage; diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index 52820eb496..d4fbabd3d5 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -47,7 +47,9 @@ INT32 main(INT32 argc, CHAR* argv[]) CHK_STATUS(initKvsWebRtc()); DLOGI("[KVS Master] KVS WebRTC initialization completed successfully"); + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = GETTIME(); CHK_STATUS(initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID)); + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime = GETTIME(); DLOGI("[KVS Master] Channel %s set up done ", pChannelName); // Checking for termination diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 34a558c45b..72814e22ec 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -41,6 +41,14 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t)); \ } while (FALSE) +#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ + do { \ + s = GETTIME(); \ + f; \ + e = GETTIME(); \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), ((e - s) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND)); \ + } while (FALSE) + #define PROFILE_WITH_START_TIME(t, msg) \ do { \ DLOGP("[%s] Time taken: %" PRIu64 " ms", msg, (GETTIME() - (t)) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index 39ac7cc438..49510f8966 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -256,6 +256,8 @@ typedef struct { UINT64 iceCandidatePairNominationTime; UINT64 candidateGatheringTime; UINT64 iceAgentSetUpTime; + UINT64 candidateGatheringStartTime; + UINT64 candidateGatheringEndTime; } KvsIceAgentStats, *PKvsIceAgentStats; /** @@ -571,6 +573,22 @@ typedef struct { * @brief SignalingClientMetrics Represent the stats related to the KVS WebRTC SDK signaling client */ typedef struct { + UINT64 signalingStartTime; + UINT64 signalingEndTime; + UINT64 offerReceiptTime; + UINT64 sendAnswerTime; + UINT64 describeChannelStartTime; + UINT64 describeChannelEndTime; + UINT64 getSignalingChannelEndpointStartTime; + UINT64 getSignalingChannelEndpointEndTime; + UINT64 getIceServerConfigStartTime; + UINT64 getIceServerConfigEndTime; + UINT64 getTokenStartTime; + UINT64 getTokenEndTime; + UINT64 createChannelStartTime; + UINT64 createChannelEndTime; + UINT64 connectStartTime; + UINT64 connectEndTime; UINT64 cpApiCallLatency; //!< Latency (in 100 ns) incurred per backend API call for the control plane APIs UINT64 dpApiCallLatency; //!< Latency (in 100 ns) incurred per backend API call for the data plane APIs UINT64 signalingClientUptime; //!< Client uptime (in 100 ns). Timestamp will be recorded at every SIGNALING_CLIENT_STATE_CONNECTED @@ -607,6 +625,8 @@ typedef struct { } SignalingClientStats, *PSignalingClientStats; typedef struct { + UINT64 peerConnectionStartTime; + UINT64 peerConnectionConnectedTime; UINT64 peerConnectionCreationTime; //!< Time taken (ms) for peer connection object creation time UINT64 dtlsSessionSetupTime; //!< Time taken (ms) for DTLS handshake to complete UINT64 iceHolePunchingTime; //!< Time taken (ms) for ICE agent set up to complete diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index 33fd9b51a8..555a465944 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -1609,6 +1609,7 @@ STATUS iceAgentGatherCandidateTimerCallback(UINT32 timerId, UINT64 currentTime, ATOMIC_STORE_BOOL(&pIceAgent->candidateGatheringFinished, TRUE); PROFILE_WITH_START_TIME_OBJ(pIceAgent->candidateGatheringStartTime, pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime, "Candidate gathering time"); + pIceAgent->candidateGatheringCalculatedEndTime = GETTIME(); /* notify that candidate gathering is finished. */ if (pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL) { pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, NULL); @@ -2844,6 +2845,8 @@ STATUS getIceAgentStats(PIceAgent pIceAgent, PKvsIceAgentMetrics pKvsIceAgentMet pKvsIceAgentMetrics->kvsIceAgentStats.iceCandidatePairNominationTime = pIceAgent->iceAgentProfileDiagnostics.iceCandidatePairNominationTime; pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringTime = pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime; pKvsIceAgentMetrics->kvsIceAgentStats.iceAgentSetUpTime = pIceAgent->iceAgentProfileDiagnostics.iceAgentSetUpTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringStartTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringEndTime = pIceAgent->candidateGatheringCalculatedEndTime; CleanUp: return retStatus; } diff --git a/src/source/Ice/IceAgent.h b/src/source/Ice/IceAgent.h index af94aa95ea..fe47f536cb 100644 --- a/src/source/Ice/IceAgent.h +++ b/src/source/Ice/IceAgent.h @@ -265,6 +265,7 @@ struct __IceAgent { PTransactionIdStore pStunBindingRequestTransactionIdStore; UINT64 candidateGatheringStartTime; + UINT64 candidateGatheringCalculatedEndTime; UINT64 iceAgentStartTime; }; diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index 458b44be05..b1304acca5 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -1267,6 +1267,18 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe pSignalingClientMetrics->signalingClientStats.fetchClientTime = pSignalingClient->diagnostics.fetchClientTime; pSignalingClientMetrics->signalingClientStats.connectClientTime = pSignalingClient->diagnostics.connectClientTime; pSignalingClientMetrics->signalingClientStats.offerToAnswerTime = pSignalingClient->diagnostics.offerToAnswerTime; + pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; + pSignalingClientMetrics->signalingClientStats.describeChannelEndTime = pSignalingClient->diagnostics.describeChannelEndTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointEndTime = pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime; + pSignalingClientMetrics->signalingClientStats.getIceServerConfigStartTime = pSignalingClient->diagnostics.getIceServerConfigStartTime; + pSignalingClientMetrics->signalingClientStats.getIceServerConfigEndTime = pSignalingClient->diagnostics.getIceServerConfigEndTime; + pSignalingClientMetrics->signalingClientStats.getTokenStartTime = pSignalingClient->diagnostics.getTokenStartTime; + pSignalingClientMetrics->signalingClientStats.getTokenEndTime = pSignalingClient->diagnostics.getTokenEndTime; + pSignalingClientMetrics->signalingClientStats.createChannelStartTime = pSignalingClient->diagnostics.createChannelStartTime; + pSignalingClientMetrics->signalingClientStats.createChannelEndTime = pSignalingClient->diagnostics.createChannelEndTime; + pSignalingClientMetrics->signalingClientStats.connectStartTime = pSignalingClient->diagnostics.connectStartTime; + pSignalingClientMetrics->signalingClientStats.connectEndTime = pSignalingClient->diagnostics.connectEndTime; case 0: // Fill in the data structures according to the version of the requested structure pSignalingClientMetrics->signalingClientStats.signalingClientUptime = curTime - pSignalingClient->diagnostics.createTime; diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 500eec44ac..2d2e0d6dc3 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -176,16 +176,28 @@ typedef struct { volatile SIZE_T numberOfErrors; volatile SIZE_T numberOfRuntimeErrors; volatile SIZE_T numberOfReconnects; + UINT64 describeChannelStartTime; + UINT64 describeChannelEndTime; + UINT64 getSignalingChannelEndpointStartTime; + UINT64 getSignalingChannelEndpointEndTime; + UINT64 getIceServerConfigStartTime; + UINT64 getIceServerConfigEndTime; + UINT64 getTokenStartTime; + UINT64 getTokenEndTime; + UINT64 createChannelStartTime; + UINT64 createChannelEndTime; + UINT64 connectStartTime; + UINT64 connectEndTime; UINT64 createTime; UINT64 connectTime; UINT64 cpApiLatency; UINT64 dpApiLatency; UINT64 getTokenCallTime; - UINT64 describeCallTime; - UINT64 createCallTime; - UINT64 getEndpointCallTime; - UINT64 getIceConfigCallTime; - UINT64 connectCallTime; + UINT64 describeCallTime; + UINT64 createCallTime; + UINT64 getEndpointCallTime; + UINT64 getIceConfigCallTime; + UINT64 connectCallTime; UINT64 createClientTime; UINT64 fetchClientTime; UINT64 connectClientTime; diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index 44462f2af7..d70e3cdb03 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -325,9 +325,9 @@ STATUS executeGetTokenSignalingState(UINT64 customData, UINT64 time) THREAD_SLEEP_UNTIL(time); // Use the credential provider to get the token - PROFILE_CALL_WITH_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, &pSignalingClient->pAwsCredentials), - pSignalingClient->diagnostics.getTokenCallTime, "Get token call"); + pSignalingClient->diagnostics.getTokenStartTime, pSignalingClient->diagnostics.getTokenEndTime, "Get token call"); // Check the expiration if (NULL == pSignalingClient->pAwsCredentials || SIGNALING_GET_CURRENT_TIME(pSignalingClient) >= pSignalingClient->pAwsCredentials->expiration) { @@ -405,8 +405,8 @@ STATUS executeDescribeSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeCallTime, - "Describe signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeChannelStartTime, + pSignalingClient->diagnostics.describeChannelEndTime, "Describe signaling call"); CleanUp: @@ -465,7 +465,8 @@ STATUS executeCreateSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createCallTime, "Create signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createChannelStartTime, + pSignalingClient->diagnostics.createChannelEndTime, "Create signaling call"); CleanUp: @@ -523,8 +524,8 @@ STATUS executeGetEndpointSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getEndpointCallTime, - "Get endpoint signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime, + pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, "Get endpoint signaling call"); CleanUp: @@ -583,8 +584,9 @@ STATUS executeGetIceConfigSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceConfigCallTime, - "Get ICE config signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceServerConfigStartTime, + pSignalingClient->diagnostics.getIceServerConfigEndTime, "Get ICE config signaling call"); + CleanUp: LEAVES(); @@ -738,8 +740,8 @@ STATUS executeConnectSignalingState(UINT64 customData, UINT64 time) SIGNALING_CLIENT_STATE_CONNECTING)); } - PROFILE_CALL_WITH_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectCallTime, - "Connect signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectStartTime, + pSignalingClient->diagnostics.connectEndTime, "Connect signaling call"); CleanUp: From 6d6b7a63da10b5761c1cb5fe0b93fac57571bcbe Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 16 Oct 2023 15:34:25 -0700 Subject: [PATCH 05/51] data channel benchmarking message --- samples/Common.c | 70 +++++++++++++++++++++++++++++++++++++++++++++-- samples/Samples.h | 11 ++++++++ 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 0ec5ee5439..ab07e3d669 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -33,15 +33,79 @@ STATUS signalingCallFailed(STATUS status) VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen) { + STATUS retStatus = STATUS_SUCCESS; + UINT32 i, strLen, tokenCount; + UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, t1, t2, t3, t4, t5; + DataChannelMessage dataChannelMessage = { '\0', '\0', '\0', '\0', '\0', '\0' }; + CHAR pMessageSend[SIZEOF(DataChannelMessage)]; + jsmn_parser parser; + jsmn_init(&parser); + jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; + + PCHAR json = (PCHAR) pMessage; + + tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); + + for (i = 1; i < tokenCount; i++) { + if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t1")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t2")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t2, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t3[0] = '\0'; + dataChannelMessage.t4[0] = '\0'; + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t3")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t4")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t4, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t5")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } + } + UNUSED_PARAM(customData); if (isBinary) { DLOGI("DataChannel Binary Message"); } else { DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); } - // Send a response to the message sent by the viewer - STATUS retStatus = STATUS_SUCCESS; - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + + if (STRLEN(dataChannelMessage.t5) == 0) { + SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, + dataChannelMessage.t1, dataChannelMessage.t2, dataChannelMessage.t3, + dataChannelMessage.t4, dataChannelMessage.t5); + DLOGI("Master's response: %s", pMessageSend); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); + } else { + STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); + STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); + STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); + masterToViewerE2E = t3 - t2; + viewerToMasterE2E = t4 - t3; + DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); + DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + } + if (retStatus != STATUS_SUCCESS) { DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); } diff --git a/samples/Samples.h b/samples/Samples.h index 1bb705b800..acf12884c1 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -51,6 +51,7 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" +#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" /* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ // #define IOT_CORE_ENABLE_CREDENTIALS 1 @@ -131,6 +132,16 @@ typedef struct { UINT32 logLevel; } SampleConfiguration, *PSampleConfiguration; +typedef struct { + CHAR content[100]; + CHAR t1[100]; + CHAR t2[100]; + CHAR t3[100]; + CHAR t4[100]; + CHAR t5[100]; +} DataChannelMessage; + + typedef struct { UINT64 hashValue; UINT64 createTime; From 30800b478cbfc86c1ecb4cb02f6b9995e130a77b Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 18 Oct 2023 15:02:54 -0700 Subject: [PATCH 06/51] fix calculation --- samples/Common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index ab07e3d669..d0a076a2e2 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -97,11 +97,12 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { + STRTOUI64(dataChannelMessage.t1, dataChannelMessage.t1 + STRLEN(dataChannelMessage.t2), 10, &t1); STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); - masterToViewerE2E = t3 - t2; - viewerToMasterE2E = t4 - t3; + masterToViewerE2E = t3 - t1; + viewerToMasterE2E = t4 - t2; DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); } From d0ecea042f92f70d7c4560a1203271e84998469c Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 30 Oct 2023 15:49:11 -0700 Subject: [PATCH 07/51] send peerconnection, iceagent, signaling metrics to viewer via dc --- samples/Common.c | 36 ++++++++++++++++++++++++++++++++++++ samples/Samples.h | 15 +++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index d0a076a2e2..e0738a777f 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -105,6 +105,9 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL viewerToMasterE2E = t4 - t2; DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); } if (retStatus != STATUS_SUCCESS) { @@ -132,8 +135,41 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); + SNPRINTF(pSignalingClientMetricsMessage, STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 13, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.cpApiCallLatency, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.dpApiCallLatency, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getEndpointCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceConfigCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectCallTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.fetchClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectClientTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + DLOGI("SIGNALING_METRICS: %s", pSignalingClientMetricsMessage); + + CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); + SNPRINTF(pPeerConnectionMetricsMessage, STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 3, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionCreationTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.dtlsSessionSetupTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.iceHolePunchingTime); + DLOGI("PEER_CONNECTION_METRICS: %s", pPeerConnectionMetricsMessage); + + CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); + SNPRINTF(pIceAgentMetricsMessage, STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 8, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.localCandidateGatheringTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.hostCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.srflxCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.relayCandidateSetUpTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceServerParsingTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceCandidatePairNominationTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceAgentSetUpTime); + DLOGI("ICE_CONNECTION_METRICS: %s", pIceAgentMetricsMessage); if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { DLOGW("Failed to get information about selected Ice candidates: 0x%08x", retStatus); diff --git a/samples/Samples.h b/samples/Samples.h index acf12884c1..a612ee0f30 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -49,12 +49,23 @@ extern "C" { #define IOT_CORE_THING_NAME ((PCHAR) "AWS_IOT_CORE_THING_NAME") #define IOT_CORE_CERTIFICATE_ID ((PCHAR) "AWS_IOT_CORE_CERTIFICATE_ID") +/* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ +// #define IOT_CORE_ENABLE_CREDENTIALS 1 + #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" #define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" +#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionCreationTime\":\"%llu\", \"dtlsSessionSetupTime\":\"%llu\", \"iceHolePunchingTime\":\"%llu\"}" +#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"cpApiCallLatency\":\"%llu\", \"dpApiCallLatency\":\"%llu\", \"getTokenCallTime\":\"%llu\", \"describeCallTime\":\"%llu\", \"createCallTime\":\"%llu\", \"getEndpointCallTime\":\"%llu\", \"getIceConfigCallTime\":\"%llu\", \"connectCallTime\":\"%llu\", \"createClientTime\":\"%llu\", \"fetchClientTime\":\"%llu\", \"connectClientTime\":\"%llu\", \"offerToAnswerTime\":\"%llu\"}" +#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"localCandidateGatheringTime\":\"%llu\", \"hostCandidateSetUpTime\":\"%llu\", \"srflxCandidateSetUpTime\":\"%llu\", \"relayCandidateSetUpTime\":\"%llu\", \"iceServerParsingTime\":\"%llu\", \"iceCandidatePairNominationTime\":\"%llu\", \"candidateGatheringTime\":\"%llu\", \"iceAgentSetUpTime\":\"%llu\"}" -/* Uncomment the following line in order to enable IoT credentials checks in the provided samples */ -// #define IOT_CORE_ENABLE_CREDENTIALS 1 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 3 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 329 + 20 * 13 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 8 + +CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; +CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; +CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; typedef enum { SAMPLE_STREAMING_VIDEO_ONLY, From 4ee043170c6eaa069ca516058cba0b9b6624ce53 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 8 Nov 2023 20:43:27 -0800 Subject: [PATCH 08/51] signaling breakdown --- samples/Common.c | 64 +++++++++++-------- samples/Samples.h | 24 +++---- samples/kvsWebRTCClientMaster.c | 2 + .../kinesis/video/webrtcclient/Include.h | 8 +++ .../kinesis/video/webrtcclient/Stats.h | 20 ++++++ src/source/Ice/IceAgent.c | 3 + src/source/Ice/IceAgent.h | 1 + src/source/Signaling/Signaling.c | 12 ++++ src/source/Signaling/Signaling.h | 22 +++++-- src/source/Signaling/StateMachine.c | 24 +++---- 10 files changed, 125 insertions(+), 55 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index e0738a777f..10db5f2f51 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -101,10 +101,13 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); + masterToViewerE2E = t3 - t1; viewerToMasterE2E = t4 - t2; + DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); @@ -135,40 +138,39 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); - SNPRINTF(pSignalingClientMetricsMessage, STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 13, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.cpApiCallLatency, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.dpApiCallLatency, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getEndpointCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceConfigCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectCallTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.fetchClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectClientTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME(); + SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + DLOGI("SIGNALING_METRICS: %s", pSignalingClientMetricsMessage); CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 3, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionCreationTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.dtlsSessionSetupTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.iceHolePunchingTime); + SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); DLOGI("PEER_CONNECTION_METRICS: %s", pPeerConnectionMetricsMessage); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 8, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.localCandidateGatheringTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.hostCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.srflxCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.relayCandidateSetUpTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceServerParsingTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceCandidatePairNominationTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.iceAgentSetUpTime); + SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); DLOGI("ICE_CONNECTION_METRICS: %s", pIceAgentMetricsMessage); if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { @@ -373,7 +375,7 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi locked = TRUE; CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); + // CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); } @@ -608,6 +610,7 @@ STATUS createSampleStreamingSession(PSampleConfiguration pSampleConfiguration, P ATOMIC_STORE_BOOL(&pSampleStreamingSession->terminateFlag, FALSE); ATOMIC_STORE_BOOL(&pSampleStreamingSession->candidateGatheringDone, FALSE); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime = GETTIME(); CHK_STATUS(initializePeerConnection(pSampleConfiguration, &pSampleStreamingSession->pPeerConnection)); CHK_STATUS(peerConnectionOnIceCandidate(pSampleStreamingSession->pPeerConnection, (UINT64) pSampleStreamingSession, onIceCandidateHandler)); CHK_STATUS( @@ -985,6 +988,8 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) STATUS retStatus = STATUS_SUCCESS; SignalingClientMetrics signalingClientMetrics = pSampleConfiguration->signalingClientMetrics; pSampleConfiguration->signalingClientCallbacks.messageReceivedFn = signalingMessageReceived; + UINT64 startTime = GETTIME(); + STRCPY(pSampleConfiguration->clientInfo.clientId, clientId); CHK_STATUS(createSignalingClientSync(&pSampleConfiguration->clientInfo, &pSampleConfiguration->channelInfo, &pSampleConfiguration->signalingClientCallbacks, pSampleConfiguration->pCredentialProvider, @@ -1007,6 +1012,7 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); pSampleConfiguration->signalingClientMetrics = signalingClientMetrics; + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = startTime; gSampleConfiguration = pSampleConfiguration; CleanUp: return retStatus; @@ -1461,6 +1467,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe switch (pReceivedSignalingMessage->signalingMessage.messageType) { case SIGNALING_MESSAGE_TYPE_OFFER: + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime = GETTIME(); // Check if we already have an ongoing master session with the same peer CHK_ERR(!peerConnectionFound, STATUS_INVALID_OPERATION, "Peer connection %s is in progress", pReceivedSignalingMessage->signalingMessage.peerClientId); @@ -1490,6 +1497,9 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock); CHK_STATUS(handleOffer(pSampleConfiguration, pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage)); + + pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime = GETTIME(); + CHK_STATUS(hashTablePut(pSampleConfiguration->pRtcPeerConnectionForRemoteClient, clientIdHash, (UINT64) pSampleStreamingSession)); // If there are any ice candidate messages in the queue for this client id, submit them now. diff --git a/samples/Samples.h b/samples/Samples.h index a612ee0f30..9fbd64b79c 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -54,14 +54,14 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" -#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\":\"%s\",\"t2\":\"%s\",\"t3\":\"%s\",\"t4\":\"%s\",\"t5\":\"%s\"}" -#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionCreationTime\":\"%llu\", \"dtlsSessionSetupTime\":\"%llu\", \"iceHolePunchingTime\":\"%llu\"}" -#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"cpApiCallLatency\":\"%llu\", \"dpApiCallLatency\":\"%llu\", \"getTokenCallTime\":\"%llu\", \"describeCallTime\":\"%llu\", \"createCallTime\":\"%llu\", \"getEndpointCallTime\":\"%llu\", \"getIceConfigCallTime\":\"%llu\", \"connectCallTime\":\"%llu\", \"createClientTime\":\"%llu\", \"fetchClientTime\":\"%llu\", \"connectClientTime\":\"%llu\", \"offerToAnswerTime\":\"%llu\"}" -#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"localCandidateGatheringTime\":\"%llu\", \"hostCandidateSetUpTime\":\"%llu\", \"srflxCandidateSetUpTime\":\"%llu\", \"relayCandidateSetUpTime\":\"%llu\", \"iceServerParsingTime\":\"%llu\", \"iceCandidatePairNominationTime\":\"%llu\", \"candidateGatheringTime\":\"%llu\", \"iceAgentSetUpTime\":\"%llu\"}" +#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" +#define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" +#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, \"describeChannelStartTime\": %llu, \"describeChannelEndTime\": %llu, \"getSignalingChannelEndpointStartTime\": %llu, \"getSignalingChannelEndpointEndTime\": %llu, \"getIceServerConfigStartTime\": %llu, \"getIceServerConfigEndTime\": %llu, \"getTokenStartTime\": %llu, \"getTokenEndTime\": %llu, \"createChannelStartTime\": %llu, \"createChannelEndTime\": %llu, \"connectStartTime\": %llu, \"connectEndTime\": %llu }" +#define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 3 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 329 + 20 * 13 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 8 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 2 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 497 + 20 * 10 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; @@ -145,11 +145,11 @@ typedef struct { typedef struct { CHAR content[100]; - CHAR t1[100]; - CHAR t2[100]; - CHAR t3[100]; - CHAR t4[100]; - CHAR t5[100]; + CHAR t1[20]; + CHAR t2[20]; + CHAR t3[20]; + CHAR t4[20]; + CHAR t5[20]; } DataChannelMessage; diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index c37e379903..d5909ce582 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -47,7 +47,9 @@ INT32 main(INT32 argc, CHAR* argv[]) CHK_STATUS(initKvsWebRtc()); DLOGI("[KVS Master] KVS WebRTC initialization completed successfully"); + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = GETTIME(); CHK_STATUS(initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID)); + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime = GETTIME(); DLOGI("[KVS Master] Channel %s set up done ", pChannelName); // Checking for termination diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 27f597c642..b1b79ee514 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -41,6 +41,14 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t)); \ } while (FALSE) +#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ + do { \ + s = GETTIME(); \ + f; \ + e = GETTIME(); \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), ((e - s) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND)); \ + } while (FALSE) + #define PROFILE_WITH_START_TIME(t, msg) \ do { \ DLOGP("[%s] Time taken: %" PRIu64 " ms", msg, (GETTIME() - (t)) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index 0b04721ee0..4b32cba4d3 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -256,6 +256,8 @@ typedef struct { UINT64 iceCandidatePairNominationTime; UINT64 candidateGatheringTime; UINT64 iceAgentSetUpTime; + UINT64 candidateGatheringStartTime; + UINT64 candidateGatheringEndTime; } KvsIceAgentStats, *PKvsIceAgentStats; /** @@ -571,6 +573,22 @@ typedef struct { * @brief SignalingClientMetrics Represent the stats related to the KVS WebRTC SDK signaling client */ typedef struct { + UINT64 signalingStartTime; + UINT64 signalingEndTime; + UINT64 offerReceiptTime; + UINT64 sendAnswerTime; + UINT64 describeChannelStartTime; + UINT64 describeChannelEndTime; + UINT64 getSignalingChannelEndpointStartTime; + UINT64 getSignalingChannelEndpointEndTime; + UINT64 getIceServerConfigStartTime; + UINT64 getIceServerConfigEndTime; + UINT64 getTokenStartTime; + UINT64 getTokenEndTime; + UINT64 createChannelStartTime; + UINT64 createChannelEndTime; + UINT64 connectStartTime; + UINT64 connectEndTime; UINT64 cpApiCallLatency; //!< Latency (in 100 ns) incurred per backend API call for the control plane APIs UINT64 dpApiCallLatency; //!< Latency (in 100 ns) incurred per backend API call for the data plane APIs UINT64 signalingClientUptime; //!< Client uptime (in 100 ns). Timestamp will be recorded at every SIGNALING_CLIENT_STATE_CONNECTED @@ -607,6 +625,8 @@ typedef struct { } SignalingClientStats, *PSignalingClientStats; typedef struct { + UINT64 peerConnectionStartTime; + UINT64 peerConnectionConnectedTime; UINT64 peerConnectionCreationTime; //!< Time taken (ms) for peer connection object creation time UINT64 dtlsSessionSetupTime; //!< Time taken (ms) for DTLS handshake to complete UINT64 iceHolePunchingTime; //!< Time taken (ms) for ICE agent set up to complete diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index bd5adc8316..5fde554469 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -1611,6 +1611,7 @@ STATUS iceAgentGatherCandidateTimerCallback(UINT32 timerId, UINT64 currentTime, ATOMIC_STORE_BOOL(&pIceAgent->candidateGatheringFinished, TRUE); PROFILE_WITH_START_TIME_OBJ(pIceAgent->candidateGatheringStartTime, pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime, "Candidate gathering time"); + pIceAgent->candidateGatheringCalculatedEndTime = GETTIME(); /* notify that candidate gathering is finished. */ if (pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL) { pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, NULL); @@ -2855,6 +2856,8 @@ STATUS getIceAgentStats(PIceAgent pIceAgent, PKvsIceAgentMetrics pKvsIceAgentMet pKvsIceAgentMetrics->kvsIceAgentStats.iceCandidatePairNominationTime = pIceAgent->iceAgentProfileDiagnostics.iceCandidatePairNominationTime; pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringTime = pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime; pKvsIceAgentMetrics->kvsIceAgentStats.iceAgentSetUpTime = pIceAgent->iceAgentProfileDiagnostics.iceAgentSetUpTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringStartTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringEndTime = pIceAgent->candidateGatheringCalculatedEndTime; CleanUp: return retStatus; } diff --git a/src/source/Ice/IceAgent.h b/src/source/Ice/IceAgent.h index af94aa95ea..fe47f536cb 100644 --- a/src/source/Ice/IceAgent.h +++ b/src/source/Ice/IceAgent.h @@ -265,6 +265,7 @@ struct __IceAgent { PTransactionIdStore pStunBindingRequestTransactionIdStore; UINT64 candidateGatheringStartTime; + UINT64 candidateGatheringCalculatedEndTime; UINT64 iceAgentStartTime; }; diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index 458b44be05..b1304acca5 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -1267,6 +1267,18 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe pSignalingClientMetrics->signalingClientStats.fetchClientTime = pSignalingClient->diagnostics.fetchClientTime; pSignalingClientMetrics->signalingClientStats.connectClientTime = pSignalingClient->diagnostics.connectClientTime; pSignalingClientMetrics->signalingClientStats.offerToAnswerTime = pSignalingClient->diagnostics.offerToAnswerTime; + pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; + pSignalingClientMetrics->signalingClientStats.describeChannelEndTime = pSignalingClient->diagnostics.describeChannelEndTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointEndTime = pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime; + pSignalingClientMetrics->signalingClientStats.getIceServerConfigStartTime = pSignalingClient->diagnostics.getIceServerConfigStartTime; + pSignalingClientMetrics->signalingClientStats.getIceServerConfigEndTime = pSignalingClient->diagnostics.getIceServerConfigEndTime; + pSignalingClientMetrics->signalingClientStats.getTokenStartTime = pSignalingClient->diagnostics.getTokenStartTime; + pSignalingClientMetrics->signalingClientStats.getTokenEndTime = pSignalingClient->diagnostics.getTokenEndTime; + pSignalingClientMetrics->signalingClientStats.createChannelStartTime = pSignalingClient->diagnostics.createChannelStartTime; + pSignalingClientMetrics->signalingClientStats.createChannelEndTime = pSignalingClient->diagnostics.createChannelEndTime; + pSignalingClientMetrics->signalingClientStats.connectStartTime = pSignalingClient->diagnostics.connectStartTime; + pSignalingClientMetrics->signalingClientStats.connectEndTime = pSignalingClient->diagnostics.connectEndTime; case 0: // Fill in the data structures according to the version of the requested structure pSignalingClientMetrics->signalingClientStats.signalingClientUptime = curTime - pSignalingClient->diagnostics.createTime; diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 500eec44ac..2d2e0d6dc3 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -176,16 +176,28 @@ typedef struct { volatile SIZE_T numberOfErrors; volatile SIZE_T numberOfRuntimeErrors; volatile SIZE_T numberOfReconnects; + UINT64 describeChannelStartTime; + UINT64 describeChannelEndTime; + UINT64 getSignalingChannelEndpointStartTime; + UINT64 getSignalingChannelEndpointEndTime; + UINT64 getIceServerConfigStartTime; + UINT64 getIceServerConfigEndTime; + UINT64 getTokenStartTime; + UINT64 getTokenEndTime; + UINT64 createChannelStartTime; + UINT64 createChannelEndTime; + UINT64 connectStartTime; + UINT64 connectEndTime; UINT64 createTime; UINT64 connectTime; UINT64 cpApiLatency; UINT64 dpApiLatency; UINT64 getTokenCallTime; - UINT64 describeCallTime; - UINT64 createCallTime; - UINT64 getEndpointCallTime; - UINT64 getIceConfigCallTime; - UINT64 connectCallTime; + UINT64 describeCallTime; + UINT64 createCallTime; + UINT64 getEndpointCallTime; + UINT64 getIceConfigCallTime; + UINT64 connectCallTime; UINT64 createClientTime; UINT64 fetchClientTime; UINT64 connectClientTime; diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index 44462f2af7..d70e3cdb03 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -325,9 +325,9 @@ STATUS executeGetTokenSignalingState(UINT64 customData, UINT64 time) THREAD_SLEEP_UNTIL(time); // Use the credential provider to get the token - PROFILE_CALL_WITH_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, &pSignalingClient->pAwsCredentials), - pSignalingClient->diagnostics.getTokenCallTime, "Get token call"); + pSignalingClient->diagnostics.getTokenStartTime, pSignalingClient->diagnostics.getTokenEndTime, "Get token call"); // Check the expiration if (NULL == pSignalingClient->pAwsCredentials || SIGNALING_GET_CURRENT_TIME(pSignalingClient) >= pSignalingClient->pAwsCredentials->expiration) { @@ -405,8 +405,8 @@ STATUS executeDescribeSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeCallTime, - "Describe signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeChannelStartTime, + pSignalingClient->diagnostics.describeChannelEndTime, "Describe signaling call"); CleanUp: @@ -465,7 +465,8 @@ STATUS executeCreateSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createCallTime, "Create signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createChannelStartTime, + pSignalingClient->diagnostics.createChannelEndTime, "Create signaling call"); CleanUp: @@ -523,8 +524,8 @@ STATUS executeGetEndpointSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getEndpointCallTime, - "Get endpoint signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime, + pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, "Get endpoint signaling call"); CleanUp: @@ -583,8 +584,9 @@ STATUS executeGetIceConfigSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceConfigCallTime, - "Get ICE config signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceServerConfigStartTime, + pSignalingClient->diagnostics.getIceServerConfigEndTime, "Get ICE config signaling call"); + CleanUp: LEAVES(); @@ -738,8 +740,8 @@ STATUS executeConnectSignalingState(UINT64 customData, UINT64 time) SIGNALING_CLIENT_STATE_CONNECTING)); } - PROFILE_CALL_WITH_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectCallTime, - "Connect signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectStartTime, + pSignalingClient->diagnostics.connectEndTime, "Connect signaling call"); CleanUp: From 435ec741883d5e7dcf5d1d738d8cb84d2e48068f Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 13 Nov 2023 11:15:18 -0800 Subject: [PATCH 09/51] cmake flag, ifdef --- CMakeLists.txt | 5 ++ samples/Common.c | 188 ++++++++++++++++++++++++---------------------- samples/Samples.h | 12 ++- 3 files changed, 110 insertions(+), 95 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a4943fd89..e000a7a7ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ option(BUILD_LIBSRTP_DESTINATION_PLATFORM "If buildng LibSRTP what is the destin option(BUILD_SAMPLE "Build available samples" ON) option(ENABLE_DATA_CHANNEL "Enable support for data channel" ON) option(ENABLE_KVS_THREADPOOL "Enable support for KVS thread pool in signaling" ON) +option(ENABLE_SENDING_METRICS_TO_VIEWER "Enable sending master-side metrics to the viewer as a json string via the datachannel" OFF) option(INSTRUMENTED_ALLOCATORS "Enable memory instrumentation" OFF) # Developer Flags @@ -103,6 +104,10 @@ if (ENABLE_KVS_THREADPOOL) add_definitions(-DENABLE_KVS_THREADPOOL) endif() +if (ENABLE_SENDING_METRICS_TO_VIEWER) + add_definitions(-DENABLE_SENDING_METRICS_TO_VIEWER) +endif() + if(USE_OPENSSL) add_definitions(-DKVS_USE_OPENSSL) elseif(USE_MBEDTLS) diff --git a/samples/Common.c b/samples/Common.c index 10db5f2f51..ad02f81970 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -34,88 +34,125 @@ STATUS signalingCallFailed(STATUS status) VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen) { STATUS retStatus = STATUS_SUCCESS; +#ifdef ENABLE_SENDING_METRICS_TO_VIEWER UINT32 i, strLen, tokenCount; UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, t1, t2, t3, t4, t5; + PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; + PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = { '\0', '\0', '\0', '\0', '\0', '\0' }; CHAR pMessageSend[SIZEOF(DataChannelMessage)]; jsmn_parser parser; jsmn_init(&parser); jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; - PCHAR json = (PCHAR) pMessage; tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); - - for (i = 1; i < tokenCount; i++) { - if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t1")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t2")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - if (strLen != 0) { - STRNCPY(dataChannelMessage.t2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { - SNPRINTF(dataChannelMessage.t2, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.t3[0] = '\0'; - dataChannelMessage.t4[0] = '\0'; - dataChannelMessage.t5[0] = '\0'; - break; - } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t3")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t4")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - if (strLen != 0) { - STRNCPY(dataChannelMessage.t4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { - SNPRINTF(dataChannelMessage.t4, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.t5[0] = '\0'; - break; + + if (tokenCount > 1) { + + CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); + DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); + + for (i = 1; i < tokenCount; i++) { + if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t1")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t2")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t2, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t3[0] = '\0'; + dataChannelMessage.t4[0] = '\0'; + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t3")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t4")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.t4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.t4, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.t5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t5")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.t5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t5")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); } - } + if (STRLEN(dataChannelMessage.t5) == 0) { + SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, + dataChannelMessage.t1, dataChannelMessage.t2, dataChannelMessage.t3, + dataChannelMessage.t4, dataChannelMessage.t5); + DLOGI("Master's response: %s", pMessageSend); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); + } else { + SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + + DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); + + CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); + SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); + + CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); + SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); + } + } else { + DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + } +#else UNUSED_PARAM(customData); if (isBinary) { DLOGI("DataChannel Binary Message"); } else { DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); } - - if (STRLEN(dataChannelMessage.t5) == 0) { - SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, - dataChannelMessage.t1, dataChannelMessage.t2, dataChannelMessage.t3, - dataChannelMessage.t4, dataChannelMessage.t5); - DLOGI("Master's response: %s", pMessageSend); - - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); - } else { - STRTOUI64(dataChannelMessage.t1, dataChannelMessage.t1 + STRLEN(dataChannelMessage.t2), 10, &t1); - STRTOUI64(dataChannelMessage.t2, dataChannelMessage.t2 + STRLEN(dataChannelMessage.t2), 10, &t2); - STRTOUI64(dataChannelMessage.t3, dataChannelMessage.t3 + STRLEN(dataChannelMessage.t3), 10, &t3); - STRTOUI64(dataChannelMessage.t4, dataChannelMessage.t4 + STRLEN(dataChannelMessage.t4), 10, &t4); - - masterToViewerE2E = t3 - t1; - viewerToMasterE2E = t4 - t2; - - DLOGI("MASTER TO VIEWER: %llu ms", masterToViewerE2E); - DLOGI("VIEWER TO MASTER: %llu ms", viewerToMasterE2E); - - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); - } - + // Send a response to the message sent by the viewer + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); +#endif if (retStatus != STATUS_SUCCESS) { DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); } + +CleanUp: + CHK_LOG_ERR(retStatus); } VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) @@ -139,39 +176,8 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta CVAR_BROADCAST(pSampleConfiguration->cvar); pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME(); - SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); - - DLOGI("SIGNALING_METRICS: %s", pSignalingClientMetricsMessage); - - CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); - DLOGI("PEER_CONNECTION_METRICS: %s", pPeerConnectionMetricsMessage); - - CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); - DLOGI("ICE_CONNECTION_METRICS: %s", pIceAgentMetricsMessage); if (STATUS_FAILED(retStatus = logSelectedIceCandidatesInformation(pSampleStreamingSession))) { DLOGW("Failed to get information about selected Ice candidates: 0x%08x", retStatus); diff --git a/samples/Samples.h b/samples/Samples.h index 9fbd64b79c..9ab6737ecd 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -54,18 +54,21 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" + +#ifdef ENABLE_SENDING_METRICS_TO_VIEWER #define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" #define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" #define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, \"describeChannelStartTime\": %llu, \"describeChannelEndTime\": %llu, \"getSignalingChannelEndpointStartTime\": %llu, \"getSignalingChannelEndpointEndTime\": %llu, \"getIceServerConfigStartTime\": %llu, \"getIceServerConfigEndTime\": %llu, \"getTokenStartTime\": %llu, \"getTokenEndTime\": %llu, \"createChannelStartTime\": %llu, \"createChannelEndTime\": %llu, \"connectStartTime\": %llu, \"connectEndTime\": %llu }" #define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 98 + 20 * 2 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 497 + 20 * 10 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 272 + 20 * 2 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; +#endif typedef enum { SAMPLE_STREAMING_VIDEO_ONLY, @@ -143,6 +146,7 @@ typedef struct { UINT32 logLevel; } SampleConfiguration, *PSampleConfiguration; +#ifdef ENABLE_SENDING_METRICS_TO_VIEWER typedef struct { CHAR content[100]; CHAR t1[20]; @@ -151,7 +155,7 @@ typedef struct { CHAR t4[20]; CHAR t5[20]; } DataChannelMessage; - +#endif typedef struct { UINT64 hashValue; From b08b79e72c51d9cd6ca4d254d3476827d66f44e9 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 13 Nov 2023 12:20:31 -0800 Subject: [PATCH 10/51] move signaling and offer / answer metrics out of signaling stats --- samples/Common.c | 16 +++++++--------- samples/kvsWebRTCClientMaster.c | 8 +++++--- .../kinesis/video/webrtcclient/Include.h | 4 ++++ .../amazonaws/kinesis/video/webrtcclient/Stats.h | 4 ---- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index ad02f81970..4de75ca5b6 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -98,10 +98,10 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, + pSampleConfiguration->signalingClientMetrics.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, @@ -381,7 +381,7 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi locked = TRUE; CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - // CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); + CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); } @@ -994,7 +994,6 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) STATUS retStatus = STATUS_SUCCESS; SignalingClientMetrics signalingClientMetrics = pSampleConfiguration->signalingClientMetrics; pSampleConfiguration->signalingClientCallbacks.messageReceivedFn = signalingMessageReceived; - UINT64 startTime = GETTIME(); STRCPY(pSampleConfiguration->clientInfo.clientId, clientId); CHK_STATUS(createSignalingClientSync(&pSampleConfiguration->clientInfo, &pSampleConfiguration->channelInfo, @@ -1018,7 +1017,6 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); pSampleConfiguration->signalingClientMetrics = signalingClientMetrics; - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = startTime; gSampleConfiguration = pSampleConfiguration; CleanUp: return retStatus; @@ -1473,7 +1471,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe switch (pReceivedSignalingMessage->signalingMessage.messageType) { case SIGNALING_MESSAGE_TYPE_OFFER: - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceiptTime = GETTIME(); + pSampleConfiguration->signalingClientMetrics.offerReceiptTime = GETTIME(); // Check if we already have an ongoing master session with the same peer CHK_ERR(!peerConnectionFound, STATUS_INVALID_OPERATION, "Peer connection %s is in progress", pReceivedSignalingMessage->signalingMessage.peerClientId); @@ -1504,7 +1502,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe CHK_STATUS(handleOffer(pSampleConfiguration, pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage)); - pSampleConfiguration->signalingClientMetrics.signalingClientStats.sendAnswerTime = GETTIME(); + pSampleConfiguration->signalingClientMetrics.sendAnswerTime = GETTIME(); CHK_STATUS(hashTablePut(pSampleConfiguration->pRtcPeerConnectionForRemoteClient, clientIdHash, (UINT64) pSampleStreamingSession)); diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index d5909ce582..411bb83c8a 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -47,9 +47,11 @@ INT32 main(INT32 argc, CHAR* argv[]) CHK_STATUS(initKvsWebRtc()); DLOGI("[KVS Master] KVS WebRTC initialization completed successfully"); - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingStartTime = GETTIME(); - CHK_STATUS(initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID)); - pSampleConfiguration->signalingClientMetrics.signalingClientStats.signalingEndTime = GETTIME(); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID), + pSampleConfiguration->signalingClientMetrics.signalingStartTime, + pSampleConfiguration->signalingClientMetrics.signalingEndTime, + "Initialize signaling client and connect to the signaling channel"); + DLOGI("[KVS Master] Channel %s set up done ", pChannelName); // Checking for termination diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index b1b79ee514..b503b5a94e 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -1515,6 +1515,10 @@ typedef struct { */ typedef struct { UINT32 version; //!< Structure version + UINT64 signalingStartTime; + UINT64 signalingEndTime; + UINT64 offerReceiptTime; + UINT64 sendAnswerTime; SignalingClientStats signalingClientStats; //!< Signaling client metrics stats. Reference in Stats.h } SignalingClientMetrics, *PSignalingClientMetrics; diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index 4b32cba4d3..c6dbaa8710 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -573,10 +573,6 @@ typedef struct { * @brief SignalingClientMetrics Represent the stats related to the KVS WebRTC SDK signaling client */ typedef struct { - UINT64 signalingStartTime; - UINT64 signalingEndTime; - UINT64 offerReceiptTime; - UINT64 sendAnswerTime; UINT64 describeChannelStartTime; UINT64 describeChannelEndTime; UINT64 getSignalingChannelEndpointStartTime; From a6bccbaca2e5e6f34dadf3da1c59223ae1fe5c81 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 13 Nov 2023 16:01:15 -0800 Subject: [PATCH 11/51] remove callTime for start and end times in signaling --- samples/Common.c | 66 +++++++++---------- .../kinesis/video/webrtcclient/Include.h | 16 +++-- .../kinesis/video/webrtcclient/Stats.h | 9 +-- src/source/Ice/IceAgent.c | 9 ++- src/source/Ice/IceAgent.h | 4 +- src/source/Signaling/LwsApiCalls.c | 4 +- src/source/Signaling/Signaling.c | 14 ++-- src/source/Signaling/Signaling.h | 10 +-- 8 files changed, 59 insertions(+), 73 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 4de75ca5b6..db303b6476 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -98,35 +98,34 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.offerReceiptTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.sendAnswerTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); - + pSampleConfiguration->signalingClientMetrics.signalingStartTime, + pSampleConfiguration->signalingClientMetrics.signalingEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); @@ -175,7 +174,7 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME(); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); @@ -382,7 +381,8 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); } CleanUp: @@ -616,7 +616,7 @@ STATUS createSampleStreamingSession(PSampleConfiguration pSampleConfiguration, P ATOMIC_STORE_BOOL(&pSampleStreamingSession->terminateFlag, FALSE); ATOMIC_STORE_BOOL(&pSampleStreamingSession->candidateGatheringDone, FALSE); - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime = GETTIME(); + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; CHK_STATUS(initializePeerConnection(pSampleConfiguration, &pSampleStreamingSession->pPeerConnection)); CHK_STATUS(peerConnectionOnIceCandidate(pSampleStreamingSession->pPeerConnection, (UINT64) pSampleStreamingSession, onIceCandidateHandler)); CHK_STATUS( @@ -1007,12 +1007,12 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &signalingClientMetrics); // Logging this here since the logs in signaling library do not get routed to file - DLOGP("[Signaling Get token] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getTokenCallTime); - DLOGP("[Signaling Describe] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.describeCallTime); - DLOGP("[Signaling Create Channel] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createCallTime); - DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getEndpointCallTime); - DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getIceConfigCallTime); - DLOGP("[Signaling Connect] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectCallTime); + DLOGP("[Signaling Get token] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getTokenEndTime - signalingClientMetrics.signalingClientStats.getTokenStartTime); + DLOGP("[Signaling Describe] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.describeChannelEndTime - signalingClientMetrics.signalingClientStats.describeChannelStartTime); + DLOGP("[Signaling Create Channel] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createChannelEndTime - signalingClientMetrics.signalingClientStats.createChannelStartTime); + DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime - signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime); + DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime - signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime); + DLOGP("[Signaling Connect] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectEndTime - signalingClientMetrics.signalingClientStats.connectStartTime); DLOGP("[Signaling create client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createClientTime); DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); @@ -1471,7 +1471,6 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe switch (pReceivedSignalingMessage->signalingMessage.messageType) { case SIGNALING_MESSAGE_TYPE_OFFER: - pSampleConfiguration->signalingClientMetrics.offerReceiptTime = GETTIME(); // Check if we already have an ongoing master session with the same peer CHK_ERR(!peerConnectionFound, STATUS_INVALID_OPERATION, "Peer connection %s is in progress", pReceivedSignalingMessage->signalingMessage.peerClientId); @@ -1502,8 +1501,6 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe CHK_STATUS(handleOffer(pSampleConfiguration, pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage)); - pSampleConfiguration->signalingClientMetrics.sendAnswerTime = GETTIME(); - CHK_STATUS(hashTablePut(pSampleConfiguration->pRtcPeerConnectionForRemoteClient, clientIdHash, (UINT64) pSampleStreamingSession)); // If there are any ice candidate messages in the queue for this client id, submit them now. @@ -1542,7 +1539,8 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe startStats = pSampleConfiguration->iceCandidatePairStatsTimerId == MAX_UINT32; CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); break; case SIGNALING_MESSAGE_TYPE_ICE_CANDIDATE: diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index b503b5a94e..449a0ee558 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -43,10 +43,10 @@ extern "C" { #define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ do { \ - s = GETTIME(); \ + s = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ f; \ - e = GETTIME(); \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), ((e - s) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND)); \ + e = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (e - s)); \ } while (FALSE) #define PROFILE_WITH_START_TIME(t, msg) \ @@ -60,6 +60,12 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), t2); \ } while (FALSE) +#define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, msg) \ + do { \ + t2 = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t2 - t1)); \ + } while (FALSE) + /*! \addtogroup StatusCodes * WEBRTC related status codes. Each value is an positive integer formed by adding * a base integer inticating the category to an index. Users may run scripts/parse_status.py @@ -1516,9 +1522,7 @@ typedef struct { typedef struct { UINT32 version; //!< Structure version UINT64 signalingStartTime; - UINT64 signalingEndTime; - UINT64 offerReceiptTime; - UINT64 sendAnswerTime; + UINT64 signalingEndTime; SignalingClientStats signalingClientStats; //!< Signaling client metrics stats. Reference in Stats.h } SignalingClientMetrics, *PSignalingClientMetrics; diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index c6dbaa8710..8ab2256016 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -607,17 +607,12 @@ typedef struct { //!< In all of these cases the error callback (if specified) will be called. UINT32 numberOfReconnects; //!< Number of reconnects in the session UINT32 apiCallRetryCount; //!< Number of retries due to API call failures in the state machine - UINT64 getTokenCallTime; //!< Time (ms) taken to get credentials for signaling - UINT64 describeCallTime; //!< Time (ms) taken to execute describeChannel call - UINT64 createCallTime; //!< Time (ms) taken to execute createChannel call - UINT64 getEndpointCallTime; //!< Time (ms) taken to execute getEndpoint call - UINT64 getIceConfigCallTime; //!< Time (ms) taken to execute getIceServerConfig call - UINT64 connectCallTime; //!< Time (ms) taken to execute connectChannel call UINT64 createClientTime; //!< Total time (ms) taken to create signaling client which includes getting credentials UINT64 fetchClientTime; //!< Total time (ms) taken to fetch signaling client which includes describe, create, get endpoint and get ICE server config UINT64 connectClientTime; //!< Total time (ms) taken to connect the signaling client which includes connecting to the signaling channel - UINT64 offerToAnswerTime; + UINT64 offerTime; + UINT64 answerTime; } SignalingClientStats, *PSignalingClientStats; typedef struct { diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index 5fde554469..ac45eb8fc8 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -599,7 +599,7 @@ STATUS iceAgentStartGathering(PIceAgent pIceAgent) CHK(!ATOMIC_LOAD_BOOL(&pIceAgent->agentStartGathering), retStatus); ATOMIC_STORE_BOOL(&pIceAgent->agentStartGathering, TRUE); - pIceAgent->candidateGatheringStartTime = GETTIME(); + pIceAgent->candidateGatheringProcessStartTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; // skip gathering host candidate and srflx candidate if relay only if (pIceAgent->iceTransportPolicy != ICE_TRANSPORT_POLICY_RELAY) { @@ -1609,9 +1609,8 @@ STATUS iceAgentGatherCandidateTimerCallback(UINT32 timerId, UINT64 currentTime, if (stopScheduling) { ATOMIC_STORE_BOOL(&pIceAgent->candidateGatheringFinished, TRUE); - PROFILE_WITH_START_TIME_OBJ(pIceAgent->candidateGatheringStartTime, pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime, + PROFILE_WITH_START_END_TIME_OBJ(pIceAgent->candidateGatheringProcessStartTime, pIceAgent->candidateGatheringProcessEndTime, "Candidate gathering time"); - pIceAgent->candidateGatheringCalculatedEndTime = GETTIME(); /* notify that candidate gathering is finished. */ if (pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL) { pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, NULL); @@ -2856,8 +2855,8 @@ STATUS getIceAgentStats(PIceAgent pIceAgent, PKvsIceAgentMetrics pKvsIceAgentMet pKvsIceAgentMetrics->kvsIceAgentStats.iceCandidatePairNominationTime = pIceAgent->iceAgentProfileDiagnostics.iceCandidatePairNominationTime; pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringTime = pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime; pKvsIceAgentMetrics->kvsIceAgentStats.iceAgentSetUpTime = pIceAgent->iceAgentProfileDiagnostics.iceAgentSetUpTime; - pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringStartTime; - pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringEndTime = pIceAgent->candidateGatheringCalculatedEndTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringProcessStartTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringEndTime = pIceAgent->candidateGatheringProcessEndTime; CleanUp: return retStatus; } diff --git a/src/source/Ice/IceAgent.h b/src/source/Ice/IceAgent.h index fe47f536cb..9196f59ce1 100644 --- a/src/source/Ice/IceAgent.h +++ b/src/source/Ice/IceAgent.h @@ -264,8 +264,8 @@ struct __IceAgent { // store transaction ids for stun binding request. PTransactionIdStore pStunBindingRequestTransactionIdStore; - UINT64 candidateGatheringStartTime; - UINT64 candidateGatheringCalculatedEndTime; + UINT64 candidateGatheringProcessStartTime; + UINT64 candidateGatheringProcessEndTime; UINT64 iceAgentStartTime; }; diff --git a/src/source/Signaling/LwsApiCalls.c b/src/source/Signaling/LwsApiCalls.c index 7ece2167ea..253add82cc 100644 --- a/src/source/Signaling/LwsApiCalls.c +++ b/src/source/Signaling/LwsApiCalls.c @@ -2175,10 +2175,10 @@ PVOID receiveLwsMessageWrapper(PVOID args) // Calling client receive message callback if specified if (pSignalingClient->signalingClientCallbacks.messageReceivedFn != NULL) { if (messageType == SIGNALING_MESSAGE_TYPE_OFFER) { - pSignalingClient->offerTime = GETTIME(); + pSignalingClient->offerTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; } if (messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); + PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); } CHK_STATUS(pSignalingClient->signalingClientCallbacks.messageReceivedFn(pSignalingClient->signalingClientCallbacks.customData, &pSignalingMessageWrapper->receivedSignalingMessage)); diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index b1304acca5..afd6d9521d 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -380,10 +380,11 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes CHK_STATUS(sendLwsMessage(pSignalingClient, pSignalingMessage->messageType, pSignalingMessage->peerClientId, pSignalingMessage->payload, pSignalingMessage->payloadLen, pSignalingMessage->correlationId, 0)); if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); + + PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { - pSignalingClient->offerTime = GETTIME(); + pSignalingClient->offerTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; } // Update the internal diagnostics only after successfully sending ATOMIC_INCREMENT(&pSignalingClient->diagnostics.numberOfMessagesSent); @@ -1257,16 +1258,11 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe switch (pSignalingClientMetrics->version) { case 1: - pSignalingClientMetrics->signalingClientStats.getTokenCallTime = pSignalingClient->diagnostics.getTokenCallTime; - pSignalingClientMetrics->signalingClientStats.describeCallTime = pSignalingClient->diagnostics.describeCallTime; - pSignalingClientMetrics->signalingClientStats.createCallTime = pSignalingClient->diagnostics.createCallTime; - pSignalingClientMetrics->signalingClientStats.getEndpointCallTime = pSignalingClient->diagnostics.getEndpointCallTime; - pSignalingClientMetrics->signalingClientStats.getIceConfigCallTime = pSignalingClient->diagnostics.getIceConfigCallTime; - pSignalingClientMetrics->signalingClientStats.connectCallTime = pSignalingClient->diagnostics.connectCallTime; pSignalingClientMetrics->signalingClientStats.createClientTime = pSignalingClient->diagnostics.createClientTime; pSignalingClientMetrics->signalingClientStats.fetchClientTime = pSignalingClient->diagnostics.fetchClientTime; pSignalingClientMetrics->signalingClientStats.connectClientTime = pSignalingClient->diagnostics.connectClientTime; - pSignalingClientMetrics->signalingClientStats.offerToAnswerTime = pSignalingClient->diagnostics.offerToAnswerTime; + pSignalingClientMetrics->signalingClientStats.answerTime = pSignalingClient->answerTime; + pSignalingClientMetrics->signalingClientStats.offerTime = pSignalingClient->offerTime; pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; pSignalingClientMetrics->signalingClientStats.describeChannelEndTime = pSignalingClient->diagnostics.describeChannelEndTime; pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime; diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 2d2e0d6dc3..4aaf4b823e 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -191,17 +191,10 @@ typedef struct { UINT64 createTime; UINT64 connectTime; UINT64 cpApiLatency; - UINT64 dpApiLatency; - UINT64 getTokenCallTime; - UINT64 describeCallTime; - UINT64 createCallTime; - UINT64 getEndpointCallTime; - UINT64 getIceConfigCallTime; - UINT64 connectCallTime; + UINT64 dpApiLatency; UINT64 createClientTime; UINT64 fetchClientTime; UINT64 connectClientTime; - UINT64 offerToAnswerTime; PHashTable pEndpointToClockSkewHashMap; UINT32 stateMachineRetryCount; } SignalingDiagnostics, PSignalingDiagnostics; @@ -351,6 +344,7 @@ typedef struct { UINT64 deleteTime; UINT64 connectTime; UINT64 offerTime; + UINT64 answerTime; } SignalingClient, *PSignalingClient; // Public handle to and from object converters From 8a932db9738ee6ad135ac3065b6bc32448346485 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 13 Nov 2023 16:20:58 -0800 Subject: [PATCH 12/51] remove new lines --- samples/Common.c | 2 -- src/source/Signaling/Signaling.c | 1 - 2 files changed, 3 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index db303b6476..f5b9612adb 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -994,7 +994,6 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) STATUS retStatus = STATUS_SUCCESS; SignalingClientMetrics signalingClientMetrics = pSampleConfiguration->signalingClientMetrics; pSampleConfiguration->signalingClientCallbacks.messageReceivedFn = signalingMessageReceived; - STRCPY(pSampleConfiguration->clientInfo.clientId, clientId); CHK_STATUS(createSignalingClientSync(&pSampleConfiguration->clientInfo, &pSampleConfiguration->channelInfo, &pSampleConfiguration->signalingClientCallbacks, pSampleConfiguration->pCredentialProvider, @@ -1500,7 +1499,6 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe MUTEX_UNLOCK(pSampleConfiguration->streamingSessionListReadLock); CHK_STATUS(handleOffer(pSampleConfiguration, pSampleStreamingSession, &pReceivedSignalingMessage->signalingMessage)); - CHK_STATUS(hashTablePut(pSampleConfiguration->pRtcPeerConnectionForRemoteClient, clientIdHash, (UINT64) pSampleStreamingSession)); // If there are any ice candidate messages in the queue for this client id, submit them now. diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index afd6d9521d..7274849bec 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -380,7 +380,6 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes CHK_STATUS(sendLwsMessage(pSignalingClient, pSignalingMessage->messageType, pSignalingMessage->peerClientId, pSignalingMessage->payload, pSignalingMessage->payloadLen, pSignalingMessage->correlationId, 0)); if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { From 8f6dfe851bf2aabd60467ecbe0825ec2f58bd863 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 13 Nov 2023 19:57:31 -0800 Subject: [PATCH 13/51] clang format --- samples/Common.c | 104 ++++++++++-------- samples/Samples.h | 15 ++- samples/kvsWebRTCClientMaster.c | 7 +- .../kinesis/video/webrtcclient/Include.h | 18 +-- src/source/Ice/IceAgent.c | 4 +- src/source/PeerConnection/Rtcp.h | 4 +- src/source/Rtp/RtpPacket.h | 2 +- src/source/Signaling/Signaling.c | 6 +- src/source/Signaling/Signaling.h | 2 +- src/source/Signaling/StateMachine.c | 22 ++-- 10 files changed, 100 insertions(+), 84 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index f5b9612adb..a204b7cc3f 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -39,7 +39,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, t1, t2, t3, t4, t5; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = { '\0', '\0', '\0', '\0', '\0', '\0' }; + DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; CHAR pMessageSend[SIZEOF(DataChannelMessage)]; jsmn_parser parser; jsmn_init(&parser); @@ -47,9 +47,8 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json = (PCHAR) pMessage; tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); - - if (tokenCount > 1) { + if (tokenCount > 1) { CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); @@ -90,43 +89,41 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL } if (STRLEN(dataChannelMessage.t5) == 0) { - SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, - dataChannelMessage.t1, dataChannelMessage.t2, dataChannelMessage.t3, - dataChannelMessage.t4, dataChannelMessage.t5); + SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, dataChannelMessage.t1, + dataChannelMessage.t2, dataChannelMessage.t3, dataChannelMessage.t4, dataChannelMessage.t5); DLOGI("Master's response: %s", pMessageSend); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); - } else { - SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingStartTime, - pSampleConfiguration->signalingClientMetrics.signalingEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); - DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); - - CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); - DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); - - CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); - DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); + } else { + SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingStartTime, pSampleConfiguration->signalingClientMetrics.signalingEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); + DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); + + CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); + SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); + DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); + + CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); + SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); + DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); @@ -174,7 +171,8 @@ VOID onConnectionStateChange(UINT64 customData, RTC_PEER_CONNECTION_STATE newSta ATOMIC_STORE_BOOL(&pSampleConfiguration->connected, TRUE); CVAR_BROADCAST(pSampleConfiguration->cvar); - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime = + GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); @@ -381,8 +379,9 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", + pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); } CleanUp: @@ -1006,12 +1005,20 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &signalingClientMetrics); // Logging this here since the logs in signaling library do not get routed to file - DLOGP("[Signaling Get token] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getTokenEndTime - signalingClientMetrics.signalingClientStats.getTokenStartTime); - DLOGP("[Signaling Describe] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.describeChannelEndTime - signalingClientMetrics.signalingClientStats.describeChannelStartTime); - DLOGP("[Signaling Create Channel] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createChannelEndTime - signalingClientMetrics.signalingClientStats.createChannelStartTime); - DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime - signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime); - DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime - signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime); - DLOGP("[Signaling Connect] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectEndTime - signalingClientMetrics.signalingClientStats.connectStartTime); + DLOGP("[Signaling Get token] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.getTokenEndTime - signalingClientMetrics.signalingClientStats.getTokenStartTime); + DLOGP("[Signaling Describe] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.describeChannelEndTime - signalingClientMetrics.signalingClientStats.describeChannelStartTime); + DLOGP("[Signaling Create Channel] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.createChannelEndTime - signalingClientMetrics.signalingClientStats.createChannelStartTime); + DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime - + signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime); + DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime - + signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime); + DLOGP("[Signaling Connect] %" PRIu64 " ms", + signalingClientMetrics.signalingClientStats.connectEndTime - signalingClientMetrics.signalingClientStats.connectStartTime); DLOGP("[Signaling create client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createClientTime); DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); @@ -1537,8 +1544,9 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe startStats = pSampleConfiguration->iceCandidatePairStatsTimerId == MAX_UINT32; CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", + pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); break; case SIGNALING_MESSAGE_TYPE_ICE_CANDIDATE: diff --git a/samples/Samples.h b/samples/Samples.h index 9ab6737ecd..58cbace96c 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -56,17 +56,22 @@ extern "C" { #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" #ifdef ENABLE_SENDING_METRICS_TO_VIEWER -#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" +#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" #define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" -#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, \"describeChannelStartTime\": %llu, \"describeChannelEndTime\": %llu, \"getSignalingChannelEndpointStartTime\": %llu, \"getSignalingChannelEndpointEndTime\": %llu, \"getIceServerConfigStartTime\": %llu, \"getIceServerConfigEndTime\": %llu, \"getTokenStartTime\": %llu, \"getTokenEndTime\": %llu, \"createChannelStartTime\": %llu, \"createChannelEndTime\": %llu, \"connectStartTime\": %llu, \"connectEndTime\": %llu }" +#define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE \ + "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, " \ + "\"describeChannelStartTime\": %llu, \"describeChannelEndTime\": %llu, \"getSignalingChannelEndpointStartTime\": %llu, " \ + "\"getSignalingChannelEndpointEndTime\": %llu, \"getIceServerConfigStartTime\": %llu, \"getIceServerConfigEndTime\": %llu, " \ + "\"getTokenStartTime\": %llu, \"getTokenEndTime\": %llu, \"createChannelStartTime\": %llu, \"createChannelEndTime\": %llu, " \ + "\"connectStartTime\": %llu, \"connectEndTime\": %llu }" #define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 #define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; -CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; +CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; #endif diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index 411bb83c8a..7ee633106a 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -47,10 +47,9 @@ INT32 main(INT32 argc, CHAR* argv[]) CHK_STATUS(initKvsWebRtc()); DLOGI("[KVS Master] KVS WebRTC initialization completed successfully"); - PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID), - pSampleConfiguration->signalingClientMetrics.signalingStartTime, - pSampleConfiguration->signalingClientMetrics.signalingEndTime, - "Initialize signaling client and connect to the signaling channel"); + PROFILE_CALL_WITH_START_END_T_OBJ( + retStatus = initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID), pSampleConfiguration->signalingClientMetrics.signalingStartTime, + pSampleConfiguration->signalingClientMetrics.signalingEndTime, "Initialize signaling client and connect to the signaling channel"); DLOGI("[KVS Master] Channel %s set up done ", pChannelName); diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 449a0ee558..6bcb317191 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -41,12 +41,12 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t)); \ } while (FALSE) -#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ +#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ do { \ - s = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ + s = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ f; \ - e = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (e - s)); \ + e = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (e - s)); \ } while (FALSE) #define PROFILE_WITH_START_TIME(t, msg) \ @@ -60,10 +60,10 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), t2); \ } while (FALSE) -#define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, msg) \ +#define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, msg) \ do { \ - t2 = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t2 - t1)); \ + t2 = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t2 - t1)); \ } while (FALSE) /*! \addtogroup StatusCodes @@ -1520,9 +1520,9 @@ typedef struct { * @brief SignalingStats Collection of signaling related stats. Can be expanded in the future */ typedef struct { - UINT32 version; //!< Structure version + UINT32 version; //!< Structure version UINT64 signalingStartTime; - UINT64 signalingEndTime; + UINT64 signalingEndTime; SignalingClientStats signalingClientStats; //!< Signaling client metrics stats. Reference in Stats.h } SignalingClientMetrics, *PSignalingClientMetrics; diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index ac45eb8fc8..833feafb4e 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -1609,8 +1609,8 @@ STATUS iceAgentGatherCandidateTimerCallback(UINT32 timerId, UINT64 currentTime, if (stopScheduling) { ATOMIC_STORE_BOOL(&pIceAgent->candidateGatheringFinished, TRUE); - PROFILE_WITH_START_END_TIME_OBJ(pIceAgent->candidateGatheringProcessStartTime, pIceAgent->candidateGatheringProcessEndTime, - "Candidate gathering time"); + PROFILE_WITH_START_END_TIME_OBJ(pIceAgent->candidateGatheringProcessStartTime, pIceAgent->candidateGatheringProcessEndTime, + "Candidate gathering time"); /* notify that candidate gathering is finished. */ if (pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL) { pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, NULL); diff --git a/src/source/PeerConnection/Rtcp.h b/src/source/PeerConnection/Rtcp.h index 229cebbe3f..513d29f0b8 100644 --- a/src/source/PeerConnection/Rtcp.h +++ b/src/source/PeerConnection/Rtcp.h @@ -31,7 +31,7 @@ typedef enum { #define TWCC_FB_PACKETCHUNK_SIZE 2 #define IS_TWCC_RUNLEN(packetChunk) ((((packetChunk) >> 15u) & 1u) == 0) #define TWCC_RUNLEN_STATUS_SYMBOL(packetChunk) (((packetChunk) >> 13u) & 3u) -#define TWCC_RUNLEN_GET(packetChunk) ((packetChunk) & 0x1fffu) +#define TWCC_RUNLEN_GET(packetChunk) ((packetChunk) &0x1fffu) #define TWCC_IS_NOTRECEIVED(statusSymbol) ((statusSymbol) == TWCC_STATUS_SYMBOL_NOTRECEIVED) #define TWCC_ISRECEIVED(statusSymbol) ((statusSymbol) == TWCC_STATUS_SYMBOL_SMALLDELTA || (statusSymbol) == TWCC_STATUS_SYMBOL_LARGEDELTA) #define TWCC_RUNLEN_ISRECEIVED(packetChunk) TWCC_ISRECEIVED(TWCC_RUNLEN_STATUS_SYMBOL(packetChunk)) @@ -39,7 +39,7 @@ typedef enum { #define TWCC_STATUSVECTOR_SSIZE(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 2u : 1u) #define TWCC_STATUSVECTOR_SMASK(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 2u : 1u) #define TWCC_STATUSVECTOR_STATUS(packetChunk, i) \ - (((packetChunk) >> (14u - (i) * TWCC_STATUSVECTOR_SSIZE(packetChunk))) & TWCC_STATUSVECTOR_SMASK(packetChunk)) + (((packetChunk) >> (14u - (i) *TWCC_STATUSVECTOR_SSIZE(packetChunk))) & TWCC_STATUSVECTOR_SMASK(packetChunk)) #define TWCC_STATUSVECTOR_COUNT(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 7 : 14) #define TWCC_PACKET_STATUS_COUNT(payload) (getUnalignedInt16BigEndian((payload) + 10)) diff --git a/src/source/Rtp/RtpPacket.h b/src/source/Rtp/RtpPacket.h index c8dc874d22..68025c7e4a 100644 --- a/src/source/Rtp/RtpPacket.h +++ b/src/source/Rtp/RtpPacket.h @@ -46,7 +46,7 @@ extern "C" { */ // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 #define TWCC_EXT_PROFILE 0xBEDE -#define TWCC_PAYLOAD(extId, sequenceNum) htonl((((extId) & 0xfu) << 28u) | (1u << 24u) | ((UINT32) (sequenceNum) << 8u)) +#define TWCC_PAYLOAD(extId, sequenceNum) htonl((((extId) &0xfu) << 28u) | (1u << 24u) | ((UINT32) (sequenceNum) << 8u)) #define TWCC_SEQNUM(extPayload) ((UINT16) getUnalignedInt16BigEndian(extPayload + 1)) typedef STATUS (*DepayRtpPayloadFunc)(PBYTE, UINT32, PBYTE, PUINT32, PBOOL); diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index 7274849bec..32c6c1f48a 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -1264,8 +1264,10 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe pSignalingClientMetrics->signalingClientStats.offerTime = pSignalingClient->offerTime; pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; pSignalingClientMetrics->signalingClientStats.describeChannelEndTime = pSignalingClient->diagnostics.describeChannelEndTime; - pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime; - pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointEndTime = pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = + pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime; + pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointEndTime = + pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime; pSignalingClientMetrics->signalingClientStats.getIceServerConfigStartTime = pSignalingClient->diagnostics.getIceServerConfigStartTime; pSignalingClientMetrics->signalingClientStats.getIceServerConfigEndTime = pSignalingClient->diagnostics.getIceServerConfigEndTime; pSignalingClientMetrics->signalingClientStats.getTokenStartTime = pSignalingClient->diagnostics.getTokenStartTime; diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 4aaf4b823e..727896774c 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -191,7 +191,7 @@ typedef struct { UINT64 createTime; UINT64 connectTime; UINT64 cpApiLatency; - UINT64 dpApiLatency; + UINT64 dpApiLatency; UINT64 createClientTime; UINT64 fetchClientTime; UINT64 connectClientTime; diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index d70e3cdb03..d1d5eed8a2 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -326,8 +326,9 @@ STATUS executeGetTokenSignalingState(UINT64 customData, UINT64 time) // Use the credential provider to get the token PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, - &pSignalingClient->pAwsCredentials), - pSignalingClient->diagnostics.getTokenStartTime, pSignalingClient->diagnostics.getTokenEndTime, "Get token call"); + &pSignalingClient->pAwsCredentials), + pSignalingClient->diagnostics.getTokenStartTime, pSignalingClient->diagnostics.getTokenEndTime, + "Get token call"); // Check the expiration if (NULL == pSignalingClient->pAwsCredentials || SIGNALING_GET_CURRENT_TIME(pSignalingClient) >= pSignalingClient->pAwsCredentials->expiration) { @@ -406,7 +407,7 @@ STATUS executeDescribeSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeChannelStartTime, - pSignalingClient->diagnostics.describeChannelEndTime, "Describe signaling call"); + pSignalingClient->diagnostics.describeChannelEndTime, "Describe signaling call"); CleanUp: @@ -465,8 +466,8 @@ STATUS executeCreateSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createChannelStartTime, - pSignalingClient->diagnostics.createChannelEndTime, "Create signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createChannelStartTime, + pSignalingClient->diagnostics.createChannelEndTime, "Create signaling call"); CleanUp: @@ -524,8 +525,9 @@ STATUS executeGetEndpointSignalingState(UINT64 customData, UINT64 time) } // Call the aggregate function - PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime, - pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, "Get endpoint signaling call"); + PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), + pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime, + pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, "Get endpoint signaling call"); CleanUp: @@ -585,8 +587,8 @@ STATUS executeGetIceConfigSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceServerConfigStartTime, - pSignalingClient->diagnostics.getIceServerConfigEndTime, "Get ICE config signaling call"); - + pSignalingClient->diagnostics.getIceServerConfigEndTime, "Get ICE config signaling call"); + CleanUp: LEAVES(); @@ -741,7 +743,7 @@ STATUS executeConnectSignalingState(UINT64 customData, UINT64 time) } PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectStartTime, - pSignalingClient->diagnostics.connectEndTime, "Connect signaling call"); + pSignalingClient->diagnostics.connectEndTime, "Connect signaling call"); CleanUp: From 9b821dc85d53ae398f5347ef9dd9986ec2d36a9f Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Tue, 14 Nov 2023 09:50:11 -0800 Subject: [PATCH 14/51] fix clang format --- src/source/PeerConnection/Rtcp.h | 4 ++-- src/source/Rtp/RtpPacket.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/source/PeerConnection/Rtcp.h b/src/source/PeerConnection/Rtcp.h index 513d29f0b8..229cebbe3f 100644 --- a/src/source/PeerConnection/Rtcp.h +++ b/src/source/PeerConnection/Rtcp.h @@ -31,7 +31,7 @@ typedef enum { #define TWCC_FB_PACKETCHUNK_SIZE 2 #define IS_TWCC_RUNLEN(packetChunk) ((((packetChunk) >> 15u) & 1u) == 0) #define TWCC_RUNLEN_STATUS_SYMBOL(packetChunk) (((packetChunk) >> 13u) & 3u) -#define TWCC_RUNLEN_GET(packetChunk) ((packetChunk) &0x1fffu) +#define TWCC_RUNLEN_GET(packetChunk) ((packetChunk) & 0x1fffu) #define TWCC_IS_NOTRECEIVED(statusSymbol) ((statusSymbol) == TWCC_STATUS_SYMBOL_NOTRECEIVED) #define TWCC_ISRECEIVED(statusSymbol) ((statusSymbol) == TWCC_STATUS_SYMBOL_SMALLDELTA || (statusSymbol) == TWCC_STATUS_SYMBOL_LARGEDELTA) #define TWCC_RUNLEN_ISRECEIVED(packetChunk) TWCC_ISRECEIVED(TWCC_RUNLEN_STATUS_SYMBOL(packetChunk)) @@ -39,7 +39,7 @@ typedef enum { #define TWCC_STATUSVECTOR_SSIZE(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 2u : 1u) #define TWCC_STATUSVECTOR_SMASK(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 2u : 1u) #define TWCC_STATUSVECTOR_STATUS(packetChunk, i) \ - (((packetChunk) >> (14u - (i) *TWCC_STATUSVECTOR_SSIZE(packetChunk))) & TWCC_STATUSVECTOR_SMASK(packetChunk)) + (((packetChunk) >> (14u - (i) * TWCC_STATUSVECTOR_SSIZE(packetChunk))) & TWCC_STATUSVECTOR_SMASK(packetChunk)) #define TWCC_STATUSVECTOR_COUNT(packetChunk) (TWCC_STATUSVECTOR_IS_2BIT(packetChunk) ? 7 : 14) #define TWCC_PACKET_STATUS_COUNT(payload) (getUnalignedInt16BigEndian((payload) + 10)) diff --git a/src/source/Rtp/RtpPacket.h b/src/source/Rtp/RtpPacket.h index 68025c7e4a..c8dc874d22 100644 --- a/src/source/Rtp/RtpPacket.h +++ b/src/source/Rtp/RtpPacket.h @@ -46,7 +46,7 @@ extern "C" { */ // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 #define TWCC_EXT_PROFILE 0xBEDE -#define TWCC_PAYLOAD(extId, sequenceNum) htonl((((extId) &0xfu) << 28u) | (1u << 24u) | ((UINT32) (sequenceNum) << 8u)) +#define TWCC_PAYLOAD(extId, sequenceNum) htonl((((extId) & 0xfu) << 28u) | (1u << 24u) | ((UINT32) (sequenceNum) << 8u)) #define TWCC_SEQNUM(extPayload) ((UINT16) getUnalignedInt16BigEndian(extPayload + 1)) typedef STATUS (*DepayRtpPayloadFunc)(PBYTE, UINT32, PBYTE, PUINT32, PBOOL); From 03c919b2a8130d0f3a3503c0db596ad88a8b79d8 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Tue, 14 Nov 2023 10:21:09 -0800 Subject: [PATCH 15/51] fix macos-gcc-ci --- src/source/Signaling/StateMachine.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index d1d5eed8a2..eff96b386b 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -309,7 +309,6 @@ STATUS executeGetTokenSignalingState(UINT64 customData, UINT64 time) STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); SERVICE_CALL_RESULT serviceCallResult; - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); @@ -393,7 +392,6 @@ STATUS executeDescribeSignalingState(UINT64 customData, UINT64 time) ENTERS(); STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); ATOMIC_STORE(&pSignalingClient->result, (SIZE_T) SERVICE_CALL_RESULT_NOT_SET); @@ -453,7 +451,6 @@ STATUS executeCreateSignalingState(UINT64 customData, UINT64 time) ENTERS(); STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); ATOMIC_STORE(&pSignalingClient->result, (SIZE_T) SERVICE_CALL_RESULT_NOT_SET); @@ -512,7 +509,6 @@ STATUS executeGetEndpointSignalingState(UINT64 customData, UINT64 time) ENTERS(); STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); ATOMIC_STORE(&pSignalingClient->result, (SIZE_T) SERVICE_CALL_RESULT_NOT_SET); @@ -573,7 +569,6 @@ STATUS executeGetIceConfigSignalingState(UINT64 customData, UINT64 time) ENTERS(); STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); ATOMIC_STORE(&pSignalingClient->result, (SIZE_T) SERVICE_CALL_RESULT_NOT_SET); @@ -732,7 +727,6 @@ STATUS executeConnectSignalingState(UINT64 customData, UINT64 time) ENTERS(); STATUS retStatus = STATUS_SUCCESS; PSignalingClient pSignalingClient = SIGNALING_CLIENT_FROM_CUSTOM_DATA(customData); - UINT64 startTimeInMacro = 0; CHK(pSignalingClient != NULL, STATUS_NULL_ARG); From ea23df4a31d279a03ee6d291d66945d99db1d521 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 15 Nov 2023 09:55:04 -0800 Subject: [PATCH 16/51] put cleanup in ifdef --- samples/Common.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/Common.c b/samples/Common.c index a204b7cc3f..29340426b4 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -147,8 +147,10 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); } +#ifdef ENABLE_SENDING_METRICS_TO_VIEWER CleanUp: CHK_LOG_ERR(retStatus); +#endif } VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) From fe1782f295ce8e0e4ce0b260c1a9fea3a93c7134 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Thu, 16 Nov 2023 12:00:23 -0800 Subject: [PATCH 17/51] add cmake flag --- .github/build_windows_openssl.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/build_windows_openssl.bat b/.github/build_windows_openssl.bat index c168aa96b4..e6901a9e04 100644 --- a/.github/build_windows_openssl.bat +++ b/.github/build_windows_openssl.bat @@ -2,5 +2,5 @@ call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Buil mkdir build cd build cmd.exe /c cmake -G "NMake Makefiles" .. -cmake -G "NMake Makefiles" -DBUILD_TEST=TRUE -DEXT_PTHREAD_INCLUDE_DIR="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/include/" -DEXT_PTHREAD_LIBRARIES="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/lib/x64/libpthreadGC2.a" .. +cmake -G "NMake Makefiles" -DENABLE_SENDING_METRICS_TO_VIEWER=ON -DBUILD_TEST=TRUE -DEXT_PTHREAD_INCLUDE_DIR="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/include/" -DEXT_PTHREAD_LIBRARIES="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/lib/x64/libpthreadGC2.a" .. nmake \ No newline at end of file From da23a0562365dd1a22a04775131dc0534916f331 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 17 Nov 2023 09:35:00 -0800 Subject: [PATCH 18/51] additional builds with cmake flags for mac and ubuntu, max string size for dc, no strlen calc in max string sizes --- .github/workflows/ci.yml | 54 ++++++++++++++++++++++++++++++++++++++++ samples/Common.c | 2 +- samples/Samples.h | 7 +++--- 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf6471baed..a68f9f7d6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,34 @@ jobs: mkdir build && cd build cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE make + - name: Run tests + run: | + cd build + ./tst/webrtc_client_test + mac-os-dc-metrics-build-clang: + runs-on: macos-11 + env: + CC: /usr/bin/clang + CXX: /usr/bin/clang++ + AWS_KVS_LOG_LEVEL: 2 + LDFLAGS: -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib + CPATH: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ + permissions: + id-token: write + contents: read + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} + aws-region: ${{ secrets.AWS_REGION }} + - name: Build repository + run: | + mkdir build && cd build + cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON -DCOMPILER_WARNINGS=TRUE + make - name: Run tests run: | cd build @@ -466,6 +494,32 @@ jobs: run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test + ubuntu-os-dc-metrics-build: + runs-on: ubuntu-20.04 + env: + AWS_KVS_LOG_LEVEL: 2 + permissions: + id-token: write + contents: read + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} + aws-region: ${{ secrets.AWS_REGION }} + - name: Build repository + run: | + # TODO: Remove the following line. This is only a workaround for enabling IPv6, https://github.com/travis-ci/travis-ci/issues/8891. + sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6' + mkdir build && cd build + cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON + make + - name: Run tests + run: | + cd build + timeout --signal=SIGABRT 60m ./tst/webrtc_client_test windows-msvc-openssl: runs-on: windows-2022 env: diff --git a/samples/Common.c b/samples/Common.c index 29340426b4..6c9bd02fe0 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -40,7 +40,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; - CHAR pMessageSend[SIZEOF(DataChannelMessage)]; + CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE]; jsmn_parser parser; jsmn_init(&parser); jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; diff --git a/samples/Samples.h b/samples/Samples.h index 58cbace96c..b9005e9a53 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -66,9 +66,10 @@ extern "C" { "\"connectStartTime\": %llu, \"connectEndTime\": %llu }" #define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE STRLEN(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE STRLEN(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE STRLEN(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 172 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 105 // strlen(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 302 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; From dde5e17dbb53e7c6f1b8d6f37bd8171d3f904408 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 17 Nov 2023 09:37:43 -0800 Subject: [PATCH 19/51] fix clang-format --- samples/Samples.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/Samples.h b/samples/Samples.h index b9005e9a53..71315b4b7d 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -66,10 +66,10 @@ extern "C" { "\"connectStartTime\": %llu, \"connectEndTime\": %llu }" #define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 172 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 -#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 105 // strlen(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 302 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 -#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 172 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 +#define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 105 // strlen(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 302 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 +#define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; From 7be92b5135865a98def853d6e1133bbf841e144c Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 17 Nov 2023 11:23:16 -0800 Subject: [PATCH 20/51] mac-os-dc-metrics-build-gcc --- .github/workflows/ci.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a68f9f7d6b..536479a0a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,14 +50,12 @@ jobs: run: | cd build ./tst/webrtc_client_test - mac-os-dc-metrics-build-clang: + mac-os-dc-metrics-build-gcc: runs-on: macos-11 env: - CC: /usr/bin/clang - CXX: /usr/bin/clang++ + CC: gcc + CXX: g++ AWS_KVS_LOG_LEVEL: 2 - LDFLAGS: -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib - CPATH: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ permissions: id-token: write contents: read @@ -72,12 +70,8 @@ jobs: - name: Build repository run: | mkdir build && cd build - cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON -DCOMPILER_WARNINGS=TRUE + cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON make - - name: Run tests - run: | - cd build - ./tst/webrtc_client_test mac-os-build-gcc: runs-on: macos-11 env: From 317c08cf7379a2e0a5ca9233af91c2af17ac7feb Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 20 Nov 2023 11:31:44 -0800 Subject: [PATCH 21/51] increase signaling metrics message size --- samples/Common.c | 2 +- samples/Samples.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 6c9bd02fe0..29340426b4 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -40,7 +40,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; - CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE]; + CHAR pMessageSend[SIZEOF(DataChannelMessage)]; jsmn_parser parser; jsmn_init(&parser); jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; diff --git a/samples/Samples.h b/samples/Samples.h index 71315b4b7d..ae32ef8dfe 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -68,7 +68,7 @@ extern "C" { #define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 172 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 #define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 105 // strlen(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 -#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 302 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 +#define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 736 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 #define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; From 81ec0ba135fbc00bdb3219718760588dc78f84ee Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 6 Dec 2023 18:22:28 -0800 Subject: [PATCH 22/51] address comments: bool, add back calltimes, remove hns --- .github/build_windows_openssl.bat | 2 +- .github/workflows/ci.yml | 48 ---- CMakeLists.txt | 5 - samples/Common.c | 205 +++++++++--------- samples/Samples.h | 15 +- samples/kvsWebRTCClientMaster.c | 3 +- .../kinesis/video/webrtcclient/Include.h | 24 +- .../kinesis/video/webrtcclient/Stats.h | 7 + src/source/Ice/IceAgent.c | 8 +- src/source/Ice/IceAgent.h | 2 +- src/source/Signaling/LwsApiCalls.c | 2 +- src/source/Signaling/Signaling.c | 10 +- src/source/Signaling/Signaling.h | 7 + src/source/Signaling/StateMachine.c | 17 +- 14 files changed, 162 insertions(+), 193 deletions(-) diff --git a/.github/build_windows_openssl.bat b/.github/build_windows_openssl.bat index e6901a9e04..c168aa96b4 100644 --- a/.github/build_windows_openssl.bat +++ b/.github/build_windows_openssl.bat @@ -2,5 +2,5 @@ call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Buil mkdir build cd build cmd.exe /c cmake -G "NMake Makefiles" .. -cmake -G "NMake Makefiles" -DENABLE_SENDING_METRICS_TO_VIEWER=ON -DBUILD_TEST=TRUE -DEXT_PTHREAD_INCLUDE_DIR="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/include/" -DEXT_PTHREAD_LIBRARIES="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/lib/x64/libpthreadGC2.a" .. +cmake -G "NMake Makefiles" -DBUILD_TEST=TRUE -DEXT_PTHREAD_INCLUDE_DIR="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/include/" -DEXT_PTHREAD_LIBRARIES="C:/tools/pthreads-w32-2-9-1-release/Pre-built.2/lib/x64/libpthreadGC2.a" .. nmake \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 536479a0a3..75bf0c8417 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,28 +50,6 @@ jobs: run: | cd build ./tst/webrtc_client_test - mac-os-dc-metrics-build-gcc: - runs-on: macos-11 - env: - CC: gcc - CXX: g++ - AWS_KVS_LOG_LEVEL: 2 - permissions: - id-token: write - contents: read - steps: - - name: Clone repository - uses: actions/checkout@v3 - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} - aws-region: ${{ secrets.AWS_REGION }} - - name: Build repository - run: | - mkdir build && cd build - cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON - make mac-os-build-gcc: runs-on: macos-11 env: @@ -488,32 +466,6 @@ jobs: run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test - ubuntu-os-dc-metrics-build: - runs-on: ubuntu-20.04 - env: - AWS_KVS_LOG_LEVEL: 2 - permissions: - id-token: write - contents: read - steps: - - name: Clone repository - uses: actions/checkout@v3 - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 - with: - role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} - aws-region: ${{ secrets.AWS_REGION }} - - name: Build repository - run: | - # TODO: Remove the following line. This is only a workaround for enabling IPv6, https://github.com/travis-ci/travis-ci/issues/8891. - sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6' - mkdir build && cd build - cmake .. -DBUILD_TEST=TRUE -DENABLE_SENDING_METRICS_TO_VIEWER=ON - make - - name: Run tests - run: | - cd build - timeout --signal=SIGABRT 60m ./tst/webrtc_client_test windows-msvc-openssl: runs-on: windows-2022 env: diff --git a/CMakeLists.txt b/CMakeLists.txt index e000a7a7ec..7a4943fd89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ option(BUILD_LIBSRTP_DESTINATION_PLATFORM "If buildng LibSRTP what is the destin option(BUILD_SAMPLE "Build available samples" ON) option(ENABLE_DATA_CHANNEL "Enable support for data channel" ON) option(ENABLE_KVS_THREADPOOL "Enable support for KVS thread pool in signaling" ON) -option(ENABLE_SENDING_METRICS_TO_VIEWER "Enable sending master-side metrics to the viewer as a json string via the datachannel" OFF) option(INSTRUMENTED_ALLOCATORS "Enable memory instrumentation" OFF) # Developer Flags @@ -104,10 +103,6 @@ if (ENABLE_KVS_THREADPOOL) add_definitions(-DENABLE_KVS_THREADPOOL) endif() -if (ENABLE_SENDING_METRICS_TO_VIEWER) - add_definitions(-DENABLE_SENDING_METRICS_TO_VIEWER) -endif() - if(USE_OPENSSL) add_definitions(-DKVS_USE_OPENSSL) elseif(USE_MBEDTLS) diff --git a/samples/Common.c b/samples/Common.c index 29340426b4..77042c0036 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -34,9 +34,8 @@ STATUS signalingCallFailed(STATUS status) VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL isBinary, PBYTE pMessage, UINT32 pMessageLen) { STATUS retStatus = STATUS_SUCCESS; -#ifdef ENABLE_SENDING_METRICS_TO_VIEWER UINT32 i, strLen, tokenCount; - UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, t1, t2, t3, t4, t5; + UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, timestamp1, timestamp2, timestamp3, timestamp4, timestamp5; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; @@ -46,111 +45,112 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; PCHAR json = (PCHAR) pMessage; - tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); - - if (tokenCount > 1) { - CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); - DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); - - for (i = 1; i < tokenCount; i++) { - if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t1")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t2")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - if (strLen != 0) { - STRNCPY(dataChannelMessage.t2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { - SNPRINTF(dataChannelMessage.t2, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.t3[0] = '\0'; - dataChannelMessage.t4[0] = '\0'; - dataChannelMessage.t5[0] = '\0'; - break; + if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { + tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); + + if (tokenCount > 1) { + CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); + DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); + + for (i = 1; i < tokenCount; i++) { + if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp1")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.timestamp1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp2")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.timestamp2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.timestamp2, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.timestamp3[0] = '\0'; + dataChannelMessage.timestamp4[0] = '\0'; + dataChannelMessage.timestamp5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp3")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.timestamp3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp4")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.timestamp4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + SNPRINTF(dataChannelMessage.timestamp4, 20, "%llu", GETTIME() / 10000); + dataChannelMessage.timestamp5[0] = '\0'; + break; + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp5")) { + strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); + STRNCPY(dataChannelMessage.timestamp5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t3")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t4")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - if (strLen != 0) { - STRNCPY(dataChannelMessage.t4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { - SNPRINTF(dataChannelMessage.t4, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.t5[0] = '\0'; - break; - } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "t5")) { - strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.t5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); } - } - if (STRLEN(dataChannelMessage.t5) == 0) { - SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, dataChannelMessage.t1, - dataChannelMessage.t2, dataChannelMessage.t3, dataChannelMessage.t4, dataChannelMessage.t5); - DLOGI("Master's response: %s", pMessageSend); + if (STRLEN(dataChannelMessage.timestamp5) == 0) { + SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, + dataChannelMessage.timestamp1, dataChannelMessage.timestamp2, dataChannelMessage.timestamp3, dataChannelMessage.timestamp4, + dataChannelMessage.timestamp5); + DLOGI("Master's response: %s", pMessageSend); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); + } else { + SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, + pSampleConfiguration->signalingClientMetrics.signalingStartTime, + pSampleConfiguration->signalingClientMetrics.signalingEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); + DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); + + CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); + SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, + pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); + DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); + + CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); + SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, + pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); + DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); + } } else { - SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingStartTime, pSampleConfiguration->signalingClientMetrics.signalingEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.getTokenEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); - DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); - - CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, - pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); - DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); - - CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, - pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); - DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); - - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); + DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); } } else { - DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); + UNUSED_PARAM(customData); + if (isBinary) { + DLOGI("DataChannel Binary Message"); + } else { + DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); + } + // Send a response to the message sent by the viewer retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); } -#else - UNUSED_PARAM(customData); - if (isBinary) { - DLOGI("DataChannel Binary Message"); - } else { - DLOGI("DataChannel String Message: %.*s\n", pMessageLen, pMessage); - } - // Send a response to the message sent by the viewer - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); -#endif if (retStatus != STATUS_SUCCESS) { DLOGI("[KVS Master] dataChannelSend(): operation returned status code: 0x%08x \n", retStatus); } -#ifdef ENABLE_SENDING_METRICS_TO_VIEWER CleanUp: CHK_LOG_ERR(retStatus); -#endif } VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) @@ -920,6 +920,7 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE * not ahead of time. */ pSampleConfiguration->trickleIce = trickleIce; pSampleConfiguration->useTurn = useTurn; + pSampleConfiguration->enableSendingMetricsToViewerViaDc = TRUE; pSampleConfiguration->channelInfo.version = CHANNEL_INFO_CURRENT_VERSION; pSampleConfiguration->channelInfo.pChannelName = channelName; @@ -1007,20 +1008,12 @@ STATUS initSignaling(PSampleConfiguration pSampleConfiguration, PCHAR clientId) signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &signalingClientMetrics); // Logging this here since the logs in signaling library do not get routed to file - DLOGP("[Signaling Get token] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.getTokenEndTime - signalingClientMetrics.signalingClientStats.getTokenStartTime); - DLOGP("[Signaling Describe] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.describeChannelEndTime - signalingClientMetrics.signalingClientStats.describeChannelStartTime); - DLOGP("[Signaling Create Channel] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.createChannelEndTime - signalingClientMetrics.signalingClientStats.createChannelStartTime); - DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointEndTime - - signalingClientMetrics.signalingClientStats.getSignalingChannelEndpointStartTime); - DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.getIceServerConfigEndTime - - signalingClientMetrics.signalingClientStats.getIceServerConfigStartTime); - DLOGP("[Signaling Connect] %" PRIu64 " ms", - signalingClientMetrics.signalingClientStats.connectEndTime - signalingClientMetrics.signalingClientStats.connectStartTime); + DLOGP("[Signaling Get token] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getTokenCallTime); + DLOGP("[Signaling Describe] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.describeCallTime); + DLOGP("[Signaling Create Channel] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createCallTime); + DLOGP("[Signaling Get endpoint] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getEndpointCallTime); + DLOGP("[Signaling Get ICE config] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.getIceConfigCallTime); + DLOGP("[Signaling Connect] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectCallTime); DLOGP("[Signaling create client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.createClientTime); DLOGP("[Signaling fetch client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.fetchClientTime); DLOGP("[Signaling connect client] %" PRIu64 " ms", signalingClientMetrics.signalingClientStats.connectClientTime); diff --git a/samples/Samples.h b/samples/Samples.h index ae32ef8dfe..312cbdf124 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -55,7 +55,6 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" -#ifdef ENABLE_SENDING_METRICS_TO_VIEWER #define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" #define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" #define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE \ @@ -74,7 +73,6 @@ extern "C" { CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; -#endif typedef enum { SAMPLE_STREAMING_VIDEO_ONLY, @@ -133,6 +131,7 @@ typedef struct { CVAR cvar; BOOL trickleIce; BOOL useTurn; + BOOL enableSendingMetricsToViewerViaDc; BOOL enableFileLogging; UINT64 customData; PSampleStreamingSession sampleStreamingSessionList[DEFAULT_MAX_CONCURRENT_STREAMING_SESSION]; @@ -152,16 +151,14 @@ typedef struct { UINT32 logLevel; } SampleConfiguration, *PSampleConfiguration; -#ifdef ENABLE_SENDING_METRICS_TO_VIEWER typedef struct { CHAR content[100]; - CHAR t1[20]; - CHAR t2[20]; - CHAR t3[20]; - CHAR t4[20]; - CHAR t5[20]; + CHAR timestamp1[20]; + CHAR timestamp2[20]; + CHAR timestamp3[20]; + CHAR timestamp4[20]; + CHAR timestamp5[20]; } DataChannelMessage; -#endif typedef struct { UINT64 hashValue; diff --git a/samples/kvsWebRTCClientMaster.c b/samples/kvsWebRTCClientMaster.c index 7ee633106a..96e3ec7593 100644 --- a/samples/kvsWebRTCClientMaster.c +++ b/samples/kvsWebRTCClientMaster.c @@ -49,7 +49,8 @@ INT32 main(INT32 argc, CHAR* argv[]) PROFILE_CALL_WITH_START_END_T_OBJ( retStatus = initSignaling(pSampleConfiguration, SAMPLE_MASTER_CLIENT_ID), pSampleConfiguration->signalingClientMetrics.signalingStartTime, - pSampleConfiguration->signalingClientMetrics.signalingEndTime, "Initialize signaling client and connect to the signaling channel"); + pSampleConfiguration->signalingClientMetrics.signalingEndTime, pSampleConfiguration->signalingClientMetrics.signalingCallTime, + "Initialize signaling client and connect to the signaling channel"); DLOGI("[KVS Master] Channel %s set up done ", pChannelName); diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index 6bcb317191..d441a2f1f7 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -41,17 +41,26 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t)); \ } while (FALSE) -#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, msg) \ +#define PROFILE_WITH_START_TIME(t, msg) \ + do { \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", msg, (GETTIME() - (t)) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ + } while (FALSE) + +#define PROFILE_CALL_WITH_START_END_T_OBJ(f, s, e, d, msg) \ do { \ s = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ f; \ e = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (e - s)); \ + d = ((e) - (s)); \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (d)); \ } while (FALSE) -#define PROFILE_WITH_START_TIME(t, msg) \ +#define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, d, msg) \ do { \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", msg, (GETTIME() - (t)) / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ + t1 = (t1 / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ + t2 = (GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND); \ + d = ((t2) - (t1)); \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (d)); \ } while (FALSE) #define PROFILE_WITH_START_TIME_OBJ(t1, t2, msg) \ @@ -60,12 +69,6 @@ extern "C" { DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), t2); \ } while (FALSE) -#define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, msg) \ - do { \ - t2 = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (t2 - t1)); \ - } while (FALSE) - /*! \addtogroup StatusCodes * WEBRTC related status codes. Each value is an positive integer formed by adding * a base integer inticating the category to an index. Users may run scripts/parse_status.py @@ -1523,6 +1526,7 @@ typedef struct { UINT32 version; //!< Structure version UINT64 signalingStartTime; UINT64 signalingEndTime; + UINT64 signalingCallTime; SignalingClientStats signalingClientStats; //!< Signaling client metrics stats. Reference in Stats.h } SignalingClientMetrics, *PSignalingClientMetrics; diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index 8ab2256016..d8daf09b62 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -607,10 +607,17 @@ typedef struct { //!< In all of these cases the error callback (if specified) will be called. UINT32 numberOfReconnects; //!< Number of reconnects in the session UINT32 apiCallRetryCount; //!< Number of retries due to API call failures in the state machine + UINT64 getTokenCallTime; //!< Time (ms) taken to get credentials for signaling + UINT64 describeCallTime; //!< Time (ms) taken to execute describeChannel call + UINT64 createCallTime; //!< Time (ms) taken to execute createChannel call + UINT64 getEndpointCallTime; //!< Time (ms) taken to execute getEndpoint call + UINT64 getIceConfigCallTime; //!< Time (ms) taken to execute getIceServerConfig call + UINT64 connectCallTime; //!< Time (ms) taken to execute connectChannel call UINT64 createClientTime; //!< Total time (ms) taken to create signaling client which includes getting credentials UINT64 fetchClientTime; //!< Total time (ms) taken to fetch signaling client which includes describe, create, get endpoint and get ICE server config UINT64 connectClientTime; //!< Total time (ms) taken to connect the signaling client which includes connecting to the signaling channel + UINT64 offerToAnswerTime; UINT64 offerTime; UINT64 answerTime; } SignalingClientStats, *PSignalingClientStats; diff --git a/src/source/Ice/IceAgent.c b/src/source/Ice/IceAgent.c index 833feafb4e..f881b816d0 100644 --- a/src/source/Ice/IceAgent.c +++ b/src/source/Ice/IceAgent.c @@ -599,7 +599,7 @@ STATUS iceAgentStartGathering(PIceAgent pIceAgent) CHK(!ATOMIC_LOAD_BOOL(&pIceAgent->agentStartGathering), retStatus); ATOMIC_STORE_BOOL(&pIceAgent->agentStartGathering, TRUE); - pIceAgent->candidateGatheringProcessStartTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; + pIceAgent->candidateGatheringStartTime = GETTIME(); // skip gathering host candidate and srflx candidate if relay only if (pIceAgent->iceTransportPolicy != ICE_TRANSPORT_POLICY_RELAY) { @@ -1609,8 +1609,8 @@ STATUS iceAgentGatherCandidateTimerCallback(UINT32 timerId, UINT64 currentTime, if (stopScheduling) { ATOMIC_STORE_BOOL(&pIceAgent->candidateGatheringFinished, TRUE); - PROFILE_WITH_START_END_TIME_OBJ(pIceAgent->candidateGatheringProcessStartTime, pIceAgent->candidateGatheringProcessEndTime, - "Candidate gathering time"); + PROFILE_WITH_START_END_TIME_OBJ(pIceAgent->candidateGatheringStartTime, pIceAgent->candidateGatheringProcessEndTime, + pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime, "Candidate gathering time"); /* notify that candidate gathering is finished. */ if (pIceAgent->iceAgentCallbacks.newLocalCandidateFn != NULL) { pIceAgent->iceAgentCallbacks.newLocalCandidateFn(pIceAgent->iceAgentCallbacks.customData, NULL); @@ -2855,7 +2855,7 @@ STATUS getIceAgentStats(PIceAgent pIceAgent, PKvsIceAgentMetrics pKvsIceAgentMet pKvsIceAgentMetrics->kvsIceAgentStats.iceCandidatePairNominationTime = pIceAgent->iceAgentProfileDiagnostics.iceCandidatePairNominationTime; pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringTime = pIceAgent->iceAgentProfileDiagnostics.candidateGatheringTime; pKvsIceAgentMetrics->kvsIceAgentStats.iceAgentSetUpTime = pIceAgent->iceAgentProfileDiagnostics.iceAgentSetUpTime; - pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringProcessStartTime; + pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringStartTime = pIceAgent->candidateGatheringStartTime; pKvsIceAgentMetrics->kvsIceAgentStats.candidateGatheringEndTime = pIceAgent->candidateGatheringProcessEndTime; CleanUp: return retStatus; diff --git a/src/source/Ice/IceAgent.h b/src/source/Ice/IceAgent.h index 9196f59ce1..bbe375cf3e 100644 --- a/src/source/Ice/IceAgent.h +++ b/src/source/Ice/IceAgent.h @@ -264,7 +264,7 @@ struct __IceAgent { // store transaction ids for stun binding request. PTransactionIdStore pStunBindingRequestTransactionIdStore; - UINT64 candidateGatheringProcessStartTime; + UINT64 candidateGatheringStartTime; UINT64 candidateGatheringProcessEndTime; UINT64 iceAgentStartTime; }; diff --git a/src/source/Signaling/LwsApiCalls.c b/src/source/Signaling/LwsApiCalls.c index 253add82cc..9050c4070d 100644 --- a/src/source/Signaling/LwsApiCalls.c +++ b/src/source/Signaling/LwsApiCalls.c @@ -2175,7 +2175,7 @@ PVOID receiveLwsMessageWrapper(PVOID args) // Calling client receive message callback if specified if (pSignalingClient->signalingClientCallbacks.messageReceivedFn != NULL) { if (messageType == SIGNALING_MESSAGE_TYPE_OFFER) { - pSignalingClient->offerTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; + pSignalingClient->offerTime = GETTIME(); } if (messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index 32c6c1f48a..ffc6f5df6e 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -380,7 +380,8 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes CHK_STATUS(sendLwsMessage(pSignalingClient, pSignalingMessage->messageType, pSignalingMessage->peerClientId, pSignalingMessage->payload, pSignalingMessage->payloadLen, pSignalingMessage->correlationId, 0)); if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); + PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, pSignalingClient->diagnostics.offerToAnswerTime, + "Offer to answer time"); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { pSignalingClient->offerTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; @@ -1257,9 +1258,16 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe switch (pSignalingClientMetrics->version) { case 1: + pSignalingClientMetrics->signalingClientStats.getTokenCallTime = pSignalingClient->diagnostics.getTokenCallTime; + pSignalingClientMetrics->signalingClientStats.describeCallTime = pSignalingClient->diagnostics.describeCallTime; + pSignalingClientMetrics->signalingClientStats.createCallTime = pSignalingClient->diagnostics.createCallTime; + pSignalingClientMetrics->signalingClientStats.getEndpointCallTime = pSignalingClient->diagnostics.getEndpointCallTime; + pSignalingClientMetrics->signalingClientStats.getIceConfigCallTime = pSignalingClient->diagnostics.getIceConfigCallTime; + pSignalingClientMetrics->signalingClientStats.connectCallTime = pSignalingClient->diagnostics.connectCallTime; pSignalingClientMetrics->signalingClientStats.createClientTime = pSignalingClient->diagnostics.createClientTime; pSignalingClientMetrics->signalingClientStats.fetchClientTime = pSignalingClient->diagnostics.fetchClientTime; pSignalingClientMetrics->signalingClientStats.connectClientTime = pSignalingClient->diagnostics.connectClientTime; + pSignalingClientMetrics->signalingClientStats.offerToAnswerTime = pSignalingClient->diagnostics.offerToAnswerTime; pSignalingClientMetrics->signalingClientStats.answerTime = pSignalingClient->answerTime; pSignalingClientMetrics->signalingClientStats.offerTime = pSignalingClient->offerTime; pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 727896774c..21e1e39658 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -192,9 +192,16 @@ typedef struct { UINT64 connectTime; UINT64 cpApiLatency; UINT64 dpApiLatency; + UINT64 getTokenCallTime; + UINT64 describeCallTime; + UINT64 createCallTime; + UINT64 getEndpointCallTime; + UINT64 getIceConfigCallTime; + UINT64 connectCallTime; UINT64 createClientTime; UINT64 fetchClientTime; UINT64 connectClientTime; + UINT64 offerToAnswerTime; PHashTable pEndpointToClockSkewHashMap; UINT32 stateMachineRetryCount; } SignalingDiagnostics, PSignalingDiagnostics; diff --git a/src/source/Signaling/StateMachine.c b/src/source/Signaling/StateMachine.c index eff96b386b..f6b153d18b 100644 --- a/src/source/Signaling/StateMachine.c +++ b/src/source/Signaling/StateMachine.c @@ -327,7 +327,7 @@ STATUS executeGetTokenSignalingState(UINT64 customData, UINT64 time) PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = pSignalingClient->pCredentialProvider->getCredentialsFn(pSignalingClient->pCredentialProvider, &pSignalingClient->pAwsCredentials), pSignalingClient->diagnostics.getTokenStartTime, pSignalingClient->diagnostics.getTokenEndTime, - "Get token call"); + pSignalingClient->diagnostics.getTokenCallTime, "Get token call"); // Check the expiration if (NULL == pSignalingClient->pAwsCredentials || SIGNALING_GET_CURRENT_TIME(pSignalingClient) >= pSignalingClient->pAwsCredentials->expiration) { @@ -405,7 +405,8 @@ STATUS executeDescribeSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = describeChannel(pSignalingClient, time), pSignalingClient->diagnostics.describeChannelStartTime, - pSignalingClient->diagnostics.describeChannelEndTime, "Describe signaling call"); + pSignalingClient->diagnostics.describeChannelEndTime, pSignalingClient->diagnostics.describeCallTime, + "Describe signaling call"); CleanUp: @@ -464,7 +465,8 @@ STATUS executeCreateSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = createChannel(pSignalingClient, time), pSignalingClient->diagnostics.createChannelStartTime, - pSignalingClient->diagnostics.createChannelEndTime, "Create signaling call"); + pSignalingClient->diagnostics.createChannelEndTime, pSignalingClient->diagnostics.createCallTime, + "Create signaling call"); CleanUp: @@ -523,7 +525,8 @@ STATUS executeGetEndpointSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getChannelEndpoint(pSignalingClient, time), pSignalingClient->diagnostics.getSignalingChannelEndpointStartTime, - pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, "Get endpoint signaling call"); + pSignalingClient->diagnostics.getSignalingChannelEndpointEndTime, + pSignalingClient->diagnostics.getEndpointCallTime, "Get endpoint signaling call"); CleanUp: @@ -582,7 +585,8 @@ STATUS executeGetIceConfigSignalingState(UINT64 customData, UINT64 time) // Call the aggregate function PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = getIceConfig(pSignalingClient, time), pSignalingClient->diagnostics.getIceServerConfigStartTime, - pSignalingClient->diagnostics.getIceServerConfigEndTime, "Get ICE config signaling call"); + pSignalingClient->diagnostics.getIceServerConfigEndTime, pSignalingClient->diagnostics.getIceConfigCallTime, + "Get ICE config signaling call"); CleanUp: @@ -737,7 +741,8 @@ STATUS executeConnectSignalingState(UINT64 customData, UINT64 time) } PROFILE_CALL_WITH_START_END_T_OBJ(retStatus = connectSignalingChannel(pSignalingClient, time), pSignalingClient->diagnostics.connectStartTime, - pSignalingClient->diagnostics.connectEndTime, "Connect signaling call"); + pSignalingClient->diagnostics.connectEndTime, pSignalingClient->diagnostics.connectCallTime, + "Connect signaling call"); CleanUp: From d743fe7f31d66fa00502b763ed6b5d6e35a0cf89 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 6 Dec 2023 18:24:14 -0800 Subject: [PATCH 23/51] missed an hns --- src/source/Signaling/Signaling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index ffc6f5df6e..acfd67a5f3 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -384,7 +384,7 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes "Offer to answer time"); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { - pSignalingClient->offerTime = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; + pSignalingClient->offerTime = GETTIME(); } // Update the internal diagnostics only after successfully sending ATOMIC_INCREMENT(&pSignalingClient->diagnostics.numberOfMessagesSent); From 7558ed48d98996b453e2723f19b93e0d8085e5fe Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 6 Dec 2023 18:31:13 -0800 Subject: [PATCH 24/51] dlogp --- samples/Common.c | 8 ++------ src/source/Signaling/Signaling.c | 3 +-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 77042c0036..bc983bb8aa 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -381,9 +381,7 @@ STATUS sendSignalingMessage(PSampleStreamingSession pSampleStreamingSession, PSi CHK_STATUS(signalingClientSendMessageSync(pSampleConfiguration->signalingClientHandle, pMessage)); if (pMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", - pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); } CleanUp: @@ -1539,9 +1537,7 @@ STATUS signalingMessageReceived(UINT64 customData, PReceivedSignalingMessage pRe startStats = pSampleConfiguration->iceCandidatePairStatsTimerId == MAX_UINT32; CHK_STATUS(signalingClientGetMetrics(pSampleConfiguration->signalingClientHandle, &pSampleConfiguration->signalingClientMetrics)); - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", - pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime - - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); break; case SIGNALING_MESSAGE_TYPE_ICE_CANDIDATE: diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index acfd67a5f3..241e723514 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -380,8 +380,7 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes CHK_STATUS(sendLwsMessage(pSignalingClient, pSignalingMessage->messageType, pSignalingMessage->peerClientId, pSignalingMessage->payload, pSignalingMessage->payloadLen, pSignalingMessage->correlationId, 0)); if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, pSignalingClient->diagnostics.offerToAnswerTime, - "Offer to answer time"); + DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { pSignalingClient->offerTime = GETTIME(); From a56346ea7831edf1efc52f0d05d2f361b54510d6 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 6 Dec 2023 18:47:18 -0800 Subject: [PATCH 25/51] fix the build --- src/source/Signaling/Signaling.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index 241e723514..f225646df2 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -380,7 +380,7 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes CHK_STATUS(sendLwsMessage(pSignalingClient, pSignalingMessage->messageType, pSignalingMessage->peerClientId, pSignalingMessage->payload, pSignalingMessage->payloadLen, pSignalingMessage->correlationId, 0)); if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - DLOGP("[Signaling offer to answer] %" PRIu64 " ms", pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerToAnswerTime); + PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); } if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { pSignalingClient->offerTime = GETTIME(); From 1bf7ffa8b3335126d8efdc29b833cbc17e8969d2 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 6 Dec 2023 18:48:13 -0800 Subject: [PATCH 26/51] remove extra space from ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75bf0c8417..bf6471baed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: - name: Run tests run: | cd build - ./tst/webrtc_client_test + ./tst/webrtc_client_test mac-os-build-gcc: runs-on: macos-11 env: From d9bdcf51cb5f4687f73c38054cc8da1314a3cb2b Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 10:55:06 -0800 Subject: [PATCH 27/51] cleanup-1 --- samples/Common.c | 1 - src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h | 2 +- src/source/Signaling/LwsApiCalls.c | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index bc983bb8aa..4c5562e51b 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -136,7 +136,6 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); } } else { - UNUSED_PARAM(customData); if (isBinary) { DLOGI("DataChannel Binary Message"); } else { diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h index d441a2f1f7..c4fc532563 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Include.h @@ -52,7 +52,7 @@ extern "C" { f; \ e = GETTIME() / HUNDREDS_OF_NANOS_IN_A_MILLISECOND; \ d = ((e) - (s)); \ - DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (d)); \ + DLOGP("[%s] Time taken: %" PRIu64 " ms", (msg), (d)); \ } while (FALSE) #define PROFILE_WITH_START_END_TIME_OBJ(t1, t2, d, msg) \ diff --git a/src/source/Signaling/LwsApiCalls.c b/src/source/Signaling/LwsApiCalls.c index 9050c4070d..4dcaa1e9bb 100644 --- a/src/source/Signaling/LwsApiCalls.c +++ b/src/source/Signaling/LwsApiCalls.c @@ -2178,7 +2178,7 @@ PVOID receiveLwsMessageWrapper(PVOID args) pSignalingClient->offerTime = GETTIME(); } if (messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, "Offer to answer time"); + PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); } CHK_STATUS(pSignalingClient->signalingClientCallbacks.messageReceivedFn(pSignalingClient->signalingClientCallbacks.customData, &pSignalingMessageWrapper->receivedSignalingMessage)); From 064027c52f643e7b2fcd1727b25f6fff686c5b24 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 10:57:12 -0800 Subject: [PATCH 28/51] clang-format --- src/source/Signaling/LwsApiCalls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/source/Signaling/LwsApiCalls.c b/src/source/Signaling/LwsApiCalls.c index 4dcaa1e9bb..ec3679df8b 100644 --- a/src/source/Signaling/LwsApiCalls.c +++ b/src/source/Signaling/LwsApiCalls.c @@ -2178,7 +2178,8 @@ PVOID receiveLwsMessageWrapper(PVOID args) pSignalingClient->offerTime = GETTIME(); } if (messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); + PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, + pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); } CHK_STATUS(pSignalingClient->signalingClientCallbacks.messageReceivedFn(pSignalingClient->signalingClientCallbacks.customData, &pSignalingMessageWrapper->receivedSignalingMessage)); From 870deb3ddaf7c3676bebd267b0d61a76ad562751 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:06:53 -0800 Subject: [PATCH 29/51] fix git_tag from master to fix the ci --- CMake/Dependencies/libkvsCommonLws-CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt b/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt index 12e513ca05..08ae3908db 100644 --- a/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt +++ b/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt @@ -6,7 +6,7 @@ include(ExternalProject) ExternalProject_Add(libkvsCommonLws-download GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git - GIT_TAG develop + GIT_TAG 178109a5dbfc5288ba5cf7fab1dc1afd5e2e182b PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${OPEN_SRC_INSTALL_PREFIX} From 435d74bbabd7657c487dcee7f29078c6361edc2e Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:20:12 -0800 Subject: [PATCH 30/51] Revert "fix git_tag from master to fix the ci" This reverts commit 870deb3ddaf7c3676bebd267b0d61a76ad562751. --- CMake/Dependencies/libkvsCommonLws-CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt b/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt index 08ae3908db..12e513ca05 100644 --- a/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt +++ b/CMake/Dependencies/libkvsCommonLws-CMakeLists.txt @@ -6,7 +6,7 @@ include(ExternalProject) ExternalProject_Add(libkvsCommonLws-download GIT_REPOSITORY https://github.com/awslabs/amazon-kinesis-video-streams-producer-c.git - GIT_TAG 178109a5dbfc5288ba5cf7fab1dc1afd5e2e182b + GIT_TAG develop PREFIX ${CMAKE_CURRENT_BINARY_DIR}/build CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${OPEN_SRC_INSTALL_PREFIX} From d34456e7029744244a174e83af7c35878921e54f Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:26:24 -0800 Subject: [PATCH 31/51] move message defs to common --- samples/Common.c | 3 +++ samples/Samples.h | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 4c5562e51b..db6b81248a 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -2,6 +2,9 @@ #include "Samples.h" PSampleConfiguration gSampleConfiguration = NULL; +CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; +CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; +CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; VOID sigintHandler(INT32 sigNum) { diff --git a/samples/Samples.h b/samples/Samples.h index 312cbdf124..953291ed55 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -70,10 +70,6 @@ extern "C" { #define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 736 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 #define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 -CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; -CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; -CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; - typedef enum { SAMPLE_STREAMING_VIDEO_ONLY, SAMPLE_STREAMING_AUDIO_VIDEO, From cc88f47501c0ae1910134b428af92142d8b42418 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:38:26 -0800 Subject: [PATCH 32/51] remove unused var --- samples/Common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index db6b81248a..b206d0298b 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -38,7 +38,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL { STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; - UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, timestamp1, timestamp2, timestamp3, timestamp4, timestamp5; + UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, timestamp1, timestamp2, timestamp4, timestamp5; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; From 271a2146bd69e27119035ea83692c0f1fda660e6 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:49:57 -0800 Subject: [PATCH 33/51] remove unused var --- samples/Common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index b206d0298b..2e1f8eda93 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -38,7 +38,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL { STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; - UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0, timestamp1, timestamp2, timestamp4, timestamp5; + UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; From 802cfa831d074044ff0bfc2b2f602370989185a6 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 11:58:34 -0800 Subject: [PATCH 34/51] cleanup-3 --- samples/Common.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 2e1f8eda93..65519c6b17 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -39,16 +39,17 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0; + CHAR pMessageSend[SIZEOF(DataChannelMessage)]; + PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; - CHAR pMessageSend[SIZEOF(DataChannelMessage)]; jsmn_parser parser; - jsmn_init(&parser); jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; - PCHAR json = (PCHAR) pMessage; if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { + jsmn_init(&parser); + json = (PCHAR) pMessage; tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); if (tokenCount > 1) { From 1e3863e52be456a20bae968ee4df1eb469d154e4 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 12:07:47 -0800 Subject: [PATCH 35/51] cleanup-4 --- samples/Common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 65519c6b17..273c7000cb 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -38,12 +38,11 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL { STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; - UINT64 masterToViewerE2E = 0, viewerToMasterE2E = 0; CHAR pMessageSend[SIZEOF(DataChannelMessage)]; PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; + DataChannelMessage dataChannelMessage = {{'\0', '\0', '\0', '\0', '\0', '\0'}}; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; From 041c858ce47adb1a812b24da86d7ac91b824fd8c Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 12:52:59 -0800 Subject: [PATCH 36/51] fix macos build --- .github/workflows/ci.yml | 6 +++--- samples/Common.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf6471baed..c6933514c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: run: | bash scripts/check-clang.sh mac-os-build-clang: - runs-on: macos-11 + runs-on: macos-13 env: CC: /usr/bin/clang CXX: /usr/bin/clang++ @@ -51,7 +51,7 @@ jobs: cd build ./tst/webrtc_client_test mac-os-build-gcc: - runs-on: macos-11 + runs-on: macos-13 env: CC: gcc CXX: g++ @@ -77,7 +77,7 @@ jobs: cd build ./tst/webrtc_client_test static-build-mac: - runs-on: macos-11 + runs-on: macos-13 env: AWS_KVS_LOG_LEVEL: 2 LDFLAGS: -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib diff --git a/samples/Common.c b/samples/Common.c index 273c7000cb..1abf870476 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -42,7 +42,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {{'\0', '\0', '\0', '\0', '\0', '\0'}}; + DataChannelMessage dataChannelMessage = {"\0", "\0", "\0", "\0", "\0", "\0"}; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; From 5b99d19ba0396a7e62c83c289fbd4e47be379122 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 13:09:49 -0800 Subject: [PATCH 37/51] Revert "fix macos build" This reverts commit 041c858ce47adb1a812b24da86d7ac91b824fd8c. --- .github/workflows/ci.yml | 6 +++--- samples/Common.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6933514c9..bf6471baed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,7 @@ jobs: run: | bash scripts/check-clang.sh mac-os-build-clang: - runs-on: macos-13 + runs-on: macos-11 env: CC: /usr/bin/clang CXX: /usr/bin/clang++ @@ -51,7 +51,7 @@ jobs: cd build ./tst/webrtc_client_test mac-os-build-gcc: - runs-on: macos-13 + runs-on: macos-11 env: CC: gcc CXX: g++ @@ -77,7 +77,7 @@ jobs: cd build ./tst/webrtc_client_test static-build-mac: - runs-on: macos-13 + runs-on: macos-11 env: AWS_KVS_LOG_LEVEL: 2 LDFLAGS: -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib diff --git a/samples/Common.c b/samples/Common.c index 1abf870476..273c7000cb 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -42,7 +42,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {"\0", "\0", "\0", "\0", "\0", "\0"}; + DataChannelMessage dataChannelMessage = {{'\0', '\0', '\0', '\0', '\0', '\0'}}; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; From 6ffbb9bdff92149f989d20db95f8df8363a47d8d Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 13:10:31 -0800 Subject: [PATCH 38/51] use double quotes instead of single for char array --- samples/Common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index 273c7000cb..1abf870476 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -42,7 +42,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {{'\0', '\0', '\0', '\0', '\0', '\0'}}; + DataChannelMessage dataChannelMessage = {"\0", "\0", "\0", "\0", "\0", "\0"}; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; From e560ad563e95bc02d4b6ad6a1c4ef010ef0d23fd Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 13:41:59 -0800 Subject: [PATCH 39/51] forgot to rename in the string --- samples/Common.c | 2 +- samples/Samples.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 1abf870476..e5240063ef 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -42,7 +42,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {"\0", "\0", "\0", "\0", "\0", "\0"}; + DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; diff --git a/samples/Samples.h b/samples/Samples.h index 953291ed55..2b7a86df3e 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -55,7 +55,8 @@ extern "C" { #define MASTER_DATA_CHANNEL_MESSAGE "This message is from the KVS Master" #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" -#define DATA_CHANNEL_MESSAGE_TEMPLATE "{\"content\":\"%s\",\"t1\": \"%s\",\"t2\": \"%s\",\"t3\": \"%s\",\"t4\": \"%s\",\"t5\": \"%s\" }" +#define DATA_CHANNEL_MESSAGE_TEMPLATE \ + "{\"content\":\"%s\",\"timestamp1\": \"%s\",\"timestamp2\": \"%s\",\"timestamp3\": \"%s\",\"timestamp4\": \"%s\",\"timestamp5\": \"%s\" }" #define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" #define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE \ "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, " \ From e430f2965613b10745b29386aaa733f2cc8028ca Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Fri, 8 Dec 2023 14:23:16 -0800 Subject: [PATCH 40/51] fix initialization + readme --- README.md | 5 +++++ samples/Common.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 307150d573..db5eac6e25 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,11 @@ The SDK also tracks entry and exit of functions which increases the verbosity of `add_definitions(-DLOG_STREAMING)` Note: This log level is extremely VERBOSE and could flood the files if using file based logging strategy. +
+ Time-to-first-frame breakdown metrics + There is a flag in the sample application which (pSampleConfiguration->enableSendingMetricsToViewerViaDc) can be set to TRUE to send metrics from the master to the [JS](https://awslabs.github.io/amazon-kinesis-video-streams-webrtc-sdk-js/examples/index.html) viewer. This helps get a detailed breakdown of time-to-first-frame and all the processes and API calls on master and the viewer both. This is intended to be used with the KVS WebRTC C SDK running as the master and the JS SDK as the viewer. The master sends peer, ice-agent, signaling and data-channel metrics to the viewer which are plotted ~ 20 seconds after the viewer is started. Since the timeline plot is intended to understand the time-to-first-frame, the sample web page needs to be refreshed and the master needs to be restarted if a new / updated plot is needed. While using the SDK in this mode, it is expected that all datachannel messages are JSON messages. This feature is only meant to be used for a single viewer at a time. +
+ ### Set path to SSL CA certificate (**Optional**) If you have a custom CA certificate path to set, you can set it using: diff --git a/samples/Common.c b/samples/Common.c index e5240063ef..03fc7d1c6b 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -42,7 +42,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; - DataChannelMessage dataChannelMessage = {'\0', '\0', '\0', '\0', '\0', '\0'}; + DataChannelMessage dataChannelMessage; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; @@ -920,7 +920,7 @@ STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE * not ahead of time. */ pSampleConfiguration->trickleIce = trickleIce; pSampleConfiguration->useTurn = useTurn; - pSampleConfiguration->enableSendingMetricsToViewerViaDc = TRUE; + pSampleConfiguration->enableSendingMetricsToViewerViaDc = FALSE; pSampleConfiguration->channelInfo.version = CHANNEL_INFO_CURRENT_VERSION; pSampleConfiguration->channelInfo.pChannelName = channelName; From 5c97ac5d56a006c3a06028116e6b200c3cf3695b Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 13:34:31 -0800 Subject: [PATCH 41/51] remove offerTime and use offerReceivedTime instead --- samples/Common.c | 2 +- .../com/amazonaws/kinesis/video/webrtcclient/Stats.h | 2 +- src/source/Signaling/LwsApiCalls.c | 7 ------- src/source/Signaling/Signaling.c | 6 +++--- src/source/Signaling/Signaling.h | 1 - 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 0ee1ec1dd8..c604f86b37 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -103,7 +103,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, pSampleConfiguration->signalingClientMetrics.signalingStartTime, pSampleConfiguration->signalingClientMetrics.signalingEndTime, - pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerTime, + pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceivedTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelStartTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.describeChannelEndTime, diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index d6ec5afcad..72fffb67ba 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -620,7 +620,7 @@ typedef struct { fetchClientTime; //!< Total time (ms) taken to fetch signaling client which includes describe, create, get endpoint and get ICE server config UINT64 connectClientTime; //!< Total time (ms) taken to connect the signaling client which includes connecting to the signaling channel UINT64 offerToAnswerTime; - UINT64 offerTime; + UINT64 offerReceivedTime; UINT64 answerTime; UINT64 joinSessionToOfferRecvTime; //!< Total time (ms) taken from joinSession call until offer is received } SignalingClientStats, *PSignalingClientStats; diff --git a/src/source/Signaling/LwsApiCalls.c b/src/source/Signaling/LwsApiCalls.c index a65cfbb5f4..b696157da7 100644 --- a/src/source/Signaling/LwsApiCalls.c +++ b/src/source/Signaling/LwsApiCalls.c @@ -2393,13 +2393,6 @@ PVOID receiveLwsMessageWrapper(PVOID args) } // Calling client receive message callback if specified if (pSignalingClient->signalingClientCallbacks.messageReceivedFn != NULL) { - if (messageType == SIGNALING_MESSAGE_TYPE_OFFER) { - pSignalingClient->offerTime = GETTIME(); - } - if (messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerTime, pSignalingClient->answerTime, - pSignalingClient->diagnostics.offerToAnswerTime, "Offer to answer time"); - } CHK_STATUS(pSignalingClient->signalingClientCallbacks.messageReceivedFn(pSignalingClient->signalingClientCallbacks.customData, &pSignalingMessageWrapper->receivedSignalingMessage)); } diff --git a/src/source/Signaling/Signaling.c b/src/source/Signaling/Signaling.c index be0bf11626..7b7a312a72 100644 --- a/src/source/Signaling/Signaling.c +++ b/src/source/Signaling/Signaling.c @@ -416,8 +416,8 @@ STATUS signalingSendMessageSync(PSignalingClient pSignalingClient, PSignalingMes if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_OFFER) { pSignalingClient->offerSentTime = GETTIME(); } else if (pSignalingMessage->messageType == SIGNALING_MESSAGE_TYPE_ANSWER) { - PROFILE_WITH_START_TIME_OBJ(pSignalingClient->offerReceivedTime, pSignalingClient->diagnostics.offerToAnswerTime, - "Offer Received to Answer Sent time"); + PROFILE_WITH_START_END_TIME_OBJ(pSignalingClient->offerReceivedTime, pSignalingClient->answerTime, + pSignalingClient->diagnostics.offerToAnswerTime, "Offer Received to Answer Sent time"); } MUTEX_UNLOCK(pSignalingClient->offerSendReceiveTimeLock); // Update the internal diagnostics only after successfully sending @@ -1423,7 +1423,7 @@ STATUS signalingGetMetrics(PSignalingClient pSignalingClient, PSignalingClientMe pSignalingClientMetrics->signalingClientStats.joinSessionCallTime = pSignalingClient->diagnostics.joinSessionCallTime; pSignalingClientMetrics->signalingClientStats.offerToAnswerTime = pSignalingClient->diagnostics.offerToAnswerTime; pSignalingClientMetrics->signalingClientStats.answerTime = pSignalingClient->answerTime; - pSignalingClientMetrics->signalingClientStats.offerTime = pSignalingClient->offerTime; + pSignalingClientMetrics->signalingClientStats.offerReceivedTime = pSignalingClient->offerReceivedTime; pSignalingClientMetrics->signalingClientStats.describeChannelStartTime = pSignalingClient->diagnostics.describeChannelStartTime; pSignalingClientMetrics->signalingClientStats.describeChannelEndTime = pSignalingClient->diagnostics.describeChannelEndTime; pSignalingClientMetrics->signalingClientStats.getSignalingChannelEndpointStartTime = diff --git a/src/source/Signaling/Signaling.h b/src/source/Signaling/Signaling.h index 9f9ae658e0..10d2813255 100644 --- a/src/source/Signaling/Signaling.h +++ b/src/source/Signaling/Signaling.h @@ -370,7 +370,6 @@ typedef struct { UINT64 deleteTime; UINT64 connectTime; UINT64 describeMediaTime; - UINT64 offerTime; UINT64 answerTime; #ifdef KVS_USE_SIGNALING_CHANNEL_THREADPOOL From 2ce7a16f91fd1645639d6945702f0c7f99d07aa7 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 13:57:24 -0800 Subject: [PATCH 42/51] move globals to streamingsession --- samples/Common.c | 29 +++++++++++++++-------------- samples/Samples.h | 3 +++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index c604f86b37..2323d20183 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -2,9 +2,6 @@ #include "Samples.h" PSampleConfiguration gSampleConfiguration = NULL; -CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; -CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; -CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; VOID sigintHandler(INT32 sigNum) { @@ -100,8 +97,8 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { - SNPRINTF(pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, - pSampleConfiguration->signalingClientMetrics.signalingStartTime, + SNPRINTF(pSampleStreamingSession->pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, + SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, pSampleConfiguration->signalingClientMetrics.signalingStartTime, pSampleConfiguration->signalingClientMetrics.signalingEndTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.offerReceivedTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.answerTime, @@ -117,23 +114,27 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL pSampleConfiguration->signalingClientMetrics.signalingClientStats.createChannelEndTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectStartTime, pSampleConfiguration->signalingClientMetrics.signalingClientStats.connectEndTime); - DLOGI("Sending signaling metrics to the viewer: %s", pSignalingClientMetricsMessage); + DLOGI("Sending signaling metrics to the viewer: %s", pSampleStreamingSession->pSignalingClientMetricsMessage); CHK_STATUS(peerConnectionGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->peerConnectionMetrics)); - SNPRINTF(pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, PEER_CONNECTION_METRICS_JSON_TEMPLATE, + SNPRINTF(pSampleStreamingSession->pPeerConnectionMetricsMessage, MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE, + PEER_CONNECTION_METRICS_JSON_TEMPLATE, pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionStartTime, pSampleStreamingSession->peerConnectionMetrics.peerConnectionStats.peerConnectionConnectedTime); - DLOGI("Sending peer-connection metrics to the viewer: %s", pPeerConnectionMetricsMessage); + DLOGI("Sending peer-connection metrics to the viewer: %s", pSampleStreamingSession->pPeerConnectionMetricsMessage); CHK_STATUS(iceAgentGetMetrics(pSampleStreamingSession->pPeerConnection, &pSampleStreamingSession->iceMetrics)); - SNPRINTF(pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, + SNPRINTF(pSampleStreamingSession->pIceAgentMetricsMessage, MAX_ICE_AGENT_METRICS_MESSAGE_SIZE, ICE_AGENT_METRICS_JSON_TEMPLATE, pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringStartTime, pSampleStreamingSession->iceMetrics.kvsIceAgentStats.candidateGatheringEndTime); - DLOGI("Sending ice-agent metrics to the viewer: %s", pIceAgentMetricsMessage); - - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSignalingClientMetricsMessage, STRLEN(pSignalingClientMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pPeerConnectionMetricsMessage, STRLEN(pPeerConnectionMetricsMessage)); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pIceAgentMetricsMessage, STRLEN(pIceAgentMetricsMessage)); + DLOGI("Sending ice-agent metrics to the viewer: %s", pSampleStreamingSession->pIceAgentMetricsMessage); + + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSampleStreamingSession->pSignalingClientMetricsMessage, + STRLEN(pSampleStreamingSession->pSignalingClientMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSampleStreamingSession->pPeerConnectionMetricsMessage, + STRLEN(pSampleStreamingSession->pPeerConnectionMetricsMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pSampleStreamingSession->pIceAgentMetricsMessage, + STRLEN(pSampleStreamingSession->pIceAgentMetricsMessage)); } } else { DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); diff --git a/samples/Samples.h b/samples/Samples.h index 67e529b2ba..8ca3e8c662 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -192,6 +192,9 @@ struct __SampleStreamingSession { UINT64 offerReceiveTime; PeerConnectionMetrics peerConnectionMetrics; KvsIceAgentMetrics iceMetrics; + CHAR pPeerConnectionMetricsMessage[MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE]; + CHAR pSignalingClientMetricsMessage[MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE]; + CHAR pIceAgentMetricsMessage[MAX_ICE_AGENT_METRICS_MESSAGE_SIZE]; }; // TODO this should all be in a higher webrtccontext layer above PeerConnection From 0f1a567334b8bf4260462f2814da49bc850f6c94 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 15:25:34 -0800 Subject: [PATCH 43/51] rename + memset --- samples/Common.c | 70 +++++++++++++++++++++++++++++++---------------- samples/Samples.h | 15 +++++----- 2 files changed, 55 insertions(+), 30 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 2323d20183..34d1991b20 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -36,7 +36,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL { STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; - CHAR pMessageSend[SIZEOF(DataChannelMessage)]; + CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE]; PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; @@ -44,11 +44,21 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; + CHK(pMessage != NULL && pDataChannel != NULL, STATUS_NULL_ARG); + if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { + jsmn_init(&parser); json = (PCHAR) pMessage; tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); + MEMSET(dataChannelMessage.content, '\0', SIZEOF(dataChannelMessage.content)); + MEMSET(dataChannelMessage.firstMessageFromViewerTs, '\0', SIZEOF(dataChannelMessage.firstMessageFromViewerTs)); + MEMSET(dataChannelMessage.firstMessageFromMasterTs, '\0', SIZEOF(dataChannelMessage.firstMessageFromMasterTs)); + MEMSET(dataChannelMessage.secondMessageFromViewerTs, '\0', SIZEOF(dataChannelMessage.secondMessageFromViewerTs)); + MEMSET(dataChannelMessage.secondMessageFromMasterTs, '\0', SIZEOF(dataChannelMessage.secondMessageFromMasterTs)); + MEMSET(dataChannelMessage.lastMessageFromViewerTs, '\0', SIZEOF(dataChannelMessage.lastMessageFromViewerTs)); + if (tokenCount > 1) { CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); @@ -56,47 +66,61 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL for (i = 1; i < tokenCount; i++) { if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "content")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp1")) { + if (strLen != 0) { + STRNCPY(dataChannelMessage.content, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "firstMessageFromViewerTs")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.timestamp1, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp2")) { + // parse and retain this message from the viewer to send it back again + if (strLen != 0) { + // since the length is not zero, we have already attached this timestamp to structure in the last iteration + STRNCPY(dataChannelMessage.firstMessageFromViewerTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "firstMessageFromMasterTs")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); if (strLen != 0) { - STRNCPY(dataChannelMessage.timestamp2, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { - SNPRINTF(dataChannelMessage.timestamp2, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.timestamp3[0] = '\0'; - dataChannelMessage.timestamp4[0] = '\0'; - dataChannelMessage.timestamp5[0] = '\0'; + // since the length is not zero, we have already attached this timestamp to structure in the last iteration + STRNCPY(dataChannelMessage.firstMessageFromMasterTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } else { + // if this timestamp was not assigned during the previous message session, add it now + SNPRINTF(dataChannelMessage.firstMessageFromMasterTs, 20, "%llu", GETTIME() / 10000); break; } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp3")) { + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "secondMessageFromViewerTs")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.timestamp3, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp4")) { + // parse and retain this message from the viewer to send it back again + if (strLen != 0) { + STRNCPY(dataChannelMessage.secondMessageFromViewerTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "secondMessageFromMasterTs")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); if (strLen != 0) { - STRNCPY(dataChannelMessage.timestamp4, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + // since the length is not zero, we have already attached this timestamp to structure in the last iteration + STRNCPY(dataChannelMessage.secondMessageFromMasterTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); } else { - SNPRINTF(dataChannelMessage.timestamp4, 20, "%llu", GETTIME() / 10000); - dataChannelMessage.timestamp5[0] = '\0'; + // if this timestamp was not assigned during the previous message session, add it now + SNPRINTF(dataChannelMessage.secondMessageFromMasterTs, 20, "%llu", GETTIME() / 10000); break; } - } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "timestamp5")) { + } else if (compareJsonString(json, &tokens[i], JSMN_STRING, (PCHAR) "lastMessageFromViewerTs")) { strLen = (UINT32) (tokens[i + 1].end - tokens[i + 1].start); - STRNCPY(dataChannelMessage.timestamp5, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + if (strLen != 0) { + STRNCPY(dataChannelMessage.lastMessageFromViewerTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); + } } } - if (STRLEN(dataChannelMessage.timestamp5) == 0) { - SNPRINTF(pMessageSend, SIZEOF(DataChannelMessage), DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, - dataChannelMessage.timestamp1, dataChannelMessage.timestamp2, dataChannelMessage.timestamp3, dataChannelMessage.timestamp4, - dataChannelMessage.timestamp5); + if (STRLEN(dataChannelMessage.lastMessageFromViewerTs) == 0) { + // continue sending the data_channel_metrics_message with new timestamps until we receive the lastMessageFromViewerTs from the viewer + SNPRINTF(pMessageSend, MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE, DATA_CHANNEL_MESSAGE_TEMPLATE, MASTER_DATA_CHANNEL_MESSAGE, + dataChannelMessage.firstMessageFromViewerTs, dataChannelMessage.firstMessageFromMasterTs, + dataChannelMessage.secondMessageFromViewerTs, dataChannelMessage.secondMessageFromMasterTs, + dataChannelMessage.lastMessageFromViewerTs); DLOGI("Master's response: %s", pMessageSend); retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) pMessageSend, STRLEN(pMessageSend)); } else { + // now that we've received the last message, send across the signaling, peerConnection, ice metrics SNPRINTF(pSampleStreamingSession->pSignalingClientMetricsMessage, MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE, SIGNALING_CLIENT_METRICS_JSON_TEMPLATE, pSampleConfiguration->signalingClientMetrics.signalingStartTime, pSampleConfiguration->signalingClientMetrics.signalingEndTime, diff --git a/samples/Samples.h b/samples/Samples.h index 8ca3e8c662..83644c0689 100644 --- a/samples/Samples.h +++ b/samples/Samples.h @@ -56,7 +56,8 @@ extern "C" { #define VIEWER_DATA_CHANNEL_MESSAGE "This message is from the KVS Viewer" #define DATA_CHANNEL_MESSAGE_TEMPLATE \ - "{\"content\":\"%s\",\"timestamp1\": \"%s\",\"timestamp2\": \"%s\",\"timestamp3\": \"%s\",\"timestamp4\": \"%s\",\"timestamp5\": \"%s\" }" + "{\"content\":\"%s\",\"firstMessageFromViewerTs\":\"%s\",\"firstMessageFromMasterTs\":\"%s\",\"secondMessageFromViewerTs\":\"%s\"," \ + "\"secondMessageFromMasterTs\":\"%s\",\"lastMessageFromViewerTs\":\"%s\" }" #define PEER_CONNECTION_METRICS_JSON_TEMPLATE "{\"peerConnectionStartTime\": %llu, \"peerConnectionEndTime\": %llu }" #define SIGNALING_CLIENT_METRICS_JSON_TEMPLATE \ "{\"signalingStartTime\": %llu, \"signalingEndTime\": %llu, \"offerReceiptTime\": %llu, \"sendAnswerTime\": %llu, " \ @@ -66,7 +67,7 @@ extern "C" { "\"connectStartTime\": %llu, \"connectEndTime\": %llu }" #define ICE_AGENT_METRICS_JSON_TEMPLATE "{\"candidateGatheringStartTime\": %llu, \"candidateGatheringEndTime\": %llu }" -#define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 172 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 +#define MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE 260 // strlen(DATA_CHANNEL_MESSAGE_TEMPLATE) + 20 * 5 #define MAX_PEER_CONNECTION_METRICS_MESSAGE_SIZE 105 // strlen(PEER_CONNECTION_METRICS_JSON_TEMPLATE) + 20 * 2 #define MAX_SIGNALING_CLIENT_METRICS_MESSAGE_SIZE 736 // strlen(SIGNALING_CLIENT_METRICS_JSON_TEMPLATE) + 20 * 10 #define MAX_ICE_AGENT_METRICS_MESSAGE_SIZE 113 // strlen(ICE_AGENT_METRICS_JSON_TEMPLATE) + 20 * 2 @@ -151,11 +152,11 @@ typedef struct { typedef struct { CHAR content[100]; - CHAR timestamp1[20]; - CHAR timestamp2[20]; - CHAR timestamp3[20]; - CHAR timestamp4[20]; - CHAR timestamp5[20]; + CHAR firstMessageFromViewerTs[20]; + CHAR firstMessageFromMasterTs[20]; + CHAR secondMessageFromViewerTs[20]; + CHAR secondMessageFromMasterTs[20]; + CHAR lastMessageFromViewerTs[20]; } DataChannelMessage; typedef struct { From f2daa198ff42e9a624bf819bab0c1174b908a39a Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 15:27:31 -0800 Subject: [PATCH 44/51] fix clang format --- samples/Common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 34d1991b20..ff9622a67f 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -47,7 +47,6 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL CHK(pMessage != NULL && pDataChannel != NULL, STATUS_NULL_ARG); if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { - jsmn_init(&parser); json = (PCHAR) pMessage; tokenCount = jsmn_parse(&parser, json, STRLEN(json), tokens, SIZEOF(tokens) / SIZEOF(jsmntok_t)); @@ -81,7 +80,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL if (strLen != 0) { // since the length is not zero, we have already attached this timestamp to structure in the last iteration STRNCPY(dataChannelMessage.firstMessageFromMasterTs, json + tokens[i + 1].start, tokens[i + 1].end - tokens[i + 1].start); - } else { + } else { // if this timestamp was not assigned during the previous message session, add it now SNPRINTF(dataChannelMessage.firstMessageFromMasterTs, 20, "%llu", GETTIME() / 10000); break; From eaa74a2e0f4e180b85180827b9f2f157f7b90aa0 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 16:12:02 -0800 Subject: [PATCH 45/51] add null check for streaming session --- samples/Common.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index ff9622a67f..8cc38dcf4c 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -44,7 +44,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; - CHK(pMessage != NULL && pDataChannel != NULL, STATUS_NULL_ARG); + CHK(pMessage != NULL && pDataChannel != NULL && pSampleStreamingSession != NULL, STATUS_NULL_ARG); if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { jsmn_init(&parser); @@ -178,6 +178,9 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL CleanUp: CHK_LOG_ERR(retStatus); + if (pSampleStreamingSession == NULL) { + DLOGE("Stats object could not be populated because of invalid arg"); + } } VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) From 5fa8636d4d8a1ce7cf5610bbc46636bb14aab55a Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Mon, 18 Dec 2023 16:30:46 -0800 Subject: [PATCH 46/51] null check for streaming session and psampleconfigurtion --- samples/Common.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 8cc38dcf4c..50c34abdf8 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -39,12 +39,25 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE]; PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; - PSampleConfiguration pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; + PSampleConfiguration pSampleConfiguration; DataChannelMessage dataChannelMessage; jsmn_parser parser; jsmntok_t tokens[MAX_JSON_TOKEN_COUNT]; - CHK(pMessage != NULL && pDataChannel != NULL && pSampleStreamingSession != NULL, STATUS_NULL_ARG); + CHK(pMessage != NULL && pDataChannel != NULL, STATUS_NULL_ARG); + + if (pSampleStreamingSession == NULL) { + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) "Could not generate stats since the streaming session is NULL", STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + DLOGE("Could not generate stats since the streaming session is NULL"); + goto CleanUp; + } + + pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; + if (pSampleConfiguration == NULL) { + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) "Could not generate stats since the sample configuration is NULL", STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + DLOGE("Could not generate stats since the sample configuration is NULL"); + goto CleanUp; + } if (pSampleConfiguration->enableSendingMetricsToViewerViaDc) { jsmn_init(&parser); @@ -178,9 +191,6 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL CleanUp: CHK_LOG_ERR(retStatus); - if (pSampleStreamingSession == NULL) { - DLOGE("Stats object could not be populated because of invalid arg"); - } } VOID onDataChannel(UINT64 customData, PRtcDataChannel pRtcDataChannel) From 0bcba8596104ed4d0d2ef4ed259a30666ec1340b Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Tue, 19 Dec 2023 11:47:54 -0800 Subject: [PATCH 47/51] add error messages --- samples/Common.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index 50c34abdf8..c52408c846 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -36,7 +36,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL { STATUS retStatus = STATUS_SUCCESS; UINT32 i, strLen, tokenCount; - CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE]; + CHAR pMessageSend[MAX_DATA_CHANNEL_METRICS_MESSAGE_SIZE], errorMessage[200]; PCHAR json; PSampleStreamingSession pSampleStreamingSession = (PSampleStreamingSession) customData; PSampleConfiguration pSampleConfiguration; @@ -47,15 +47,17 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL CHK(pMessage != NULL && pDataChannel != NULL, STATUS_NULL_ARG); if (pSampleStreamingSession == NULL) { - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) "Could not generate stats since the streaming session is NULL", STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); - DLOGE("Could not generate stats since the streaming session is NULL"); + STRCPY(errorMessage, "Could not generate stats since the streaming session is NULL"); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); + DLOGE("%s", errorMessage); goto CleanUp; } - + pSampleConfiguration = pSampleStreamingSession->pSampleConfiguration; if (pSampleConfiguration == NULL) { - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) "Could not generate stats since the sample configuration is NULL", STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); - DLOGE("Could not generate stats since the sample configuration is NULL"); + STRCPY(errorMessage, "Could not generate stats since the sample configuration is NULL"); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); + DLOGE("%s", errorMessage); goto CleanUp; } @@ -174,7 +176,9 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL } } else { DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); - retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) MASTER_DATA_CHANNEL_MESSAGE, STRLEN(MASTER_DATA_CHANNEL_MESSAGE)); + STRCPY(errorMessage, "Send a json message for benchmarking as the C SDK is operating in benchmarking mode"); + retStatus = + dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); } } else { if (isBinary) { From af07dbff32ebfc20c7a6581a196db28e2f2d7d95 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Tue, 19 Dec 2023 11:50:40 -0800 Subject: [PATCH 48/51] clang --- samples/Common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/Common.c b/samples/Common.c index c52408c846..ebe49804ac 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -177,8 +177,7 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL } else { DLOGI("DataChannel string message: %.*s\n", pMessageLen, pMessage); STRCPY(errorMessage, "Send a json message for benchmarking as the C SDK is operating in benchmarking mode"); - retStatus = - dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); } } else { if (isBinary) { From ebcdc4116e4f3de9d09f28519867208d60d2caeb Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Tue, 19 Dec 2023 20:52:58 -0800 Subject: [PATCH 49/51] error message --- samples/Common.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index ebe49804ac..1518cee1e6 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -74,7 +74,13 @@ VOID onDataChannelMessage(UINT64 customData, PRtcDataChannel pDataChannel, BOOL MEMSET(dataChannelMessage.lastMessageFromViewerTs, '\0', SIZEOF(dataChannelMessage.lastMessageFromViewerTs)); if (tokenCount > 1) { - CHK(tokens[0].type == JSMN_OBJECT, STATUS_INVALID_API_CALL_RETURN_JSON); + if (tokens[0].type != JSMN_OBJECT) { + STRCPY(errorMessage, "Invalid JSON received, please send a valid json as the SDK is operating in datachannel-benchmarking mode"); + retStatus = dataChannelSend(pDataChannel, FALSE, (PBYTE) errorMessage, STRLEN(errorMessage)); + DLOGE("%s", errorMessage); + retStatus = STATUS_INVALID_API_CALL_RETURN_JSON; + goto CleanUp; + } DLOGI("DataChannel json message: %.*s\n", pMessageLen, pMessage); for (i = 1; i < tokenCount; i++) { From 9f8d6ed6453f7c7e7bf41d93a9cd5d16b3a950b5 Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 20 Dec 2023 13:15:05 -0800 Subject: [PATCH 50/51] ubuntu sample check update --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 55b77db60f..178833ee7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -416,7 +416,7 @@ jobs: timeout --signal=SIGABRT 60m ./tst/webrtc_client_test sample-check: if: github.repository == 'awslabs/amazon-kinesis-video-streams-webrtc-sdk-c' - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest env: AWS_KVS_LOG_LEVEL: 2 permissions: @@ -424,19 +424,21 @@ jobs: contents: read steps: - name: Clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v2 + uses: aws-actions/configure-aws-credentials@v4 with: role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} aws-region: ${{ secrets.AWS_REGION }} + role-duration-seconds: 10800 - name: Build repository run: | sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6' mkdir build && cd build cmake .. make - cd .. + - name: Sample check + run: | ./scripts/check-sample.sh ubuntu-os-build: runs-on: ubuntu-20.04 From 15d7fabc0857451159470efa68c4835ea49b199e Mon Sep 17 00:00:00 2001 From: Niyati Maheshwari Date: Wed, 20 Dec 2023 15:09:14 -0800 Subject: [PATCH 51/51] fix sample check --- scripts/check-sample.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/check-sample.sh b/scripts/check-sample.sh index 3615265174..d4d8cdbe5b 100755 --- a/scripts/check-sample.sh +++ b/scripts/check-sample.sh @@ -1,14 +1,11 @@ #!/bin/bash -if [[ -z "$AWS_ACCESS_KEY_ID" || -z "$AWS_SECRET_ACCESS_KEY" ]] +if [[ -z "$AWS_ACCESS_KEY_ID" || -z "$AWS_SECRET_ACCESS_KEY" || -z "$AWS_SESSION_TOKEN" ]] then echo "Couldn't find AWS credentials. Very likely this build is coming from a fork. Ignoring." exit 0 fi -# Set session token to empty string to check that it gets ignored -export AWS_SESSION_TOKEN= - # Set bash to print out every command that's running to the screen # Set logging after checking credentials so that we don't leak them set -xv