diff --git a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h index 39ac7cc438..0b04721ee0 100644 --- a/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h +++ b/src/include/com/amazonaws/kinesis/video/webrtcclient/Stats.h @@ -612,6 +612,7 @@ typedef struct { UINT64 iceHolePunchingTime; //!< Time taken (ms) for ICE agent set up to complete UINT64 closePeerConnectionTime; //!< Time taken (ms) to close the peer connection UINT64 freePeerConnectionTime; //!< Time taken (ms) to free the peer connection object + UINT64 stunDnsResolutionTime; //!< Time taken (ms) to complete STUN DNS resolution on the thread } PeerConnectionStats, *PPeerConnectionStats; /** diff --git a/src/source/PeerConnection/PeerConnection.c b/src/source/PeerConnection/PeerConnection.c index c79eb24634..49b05ab4e8 100644 --- a/src/source/PeerConnection/PeerConnection.c +++ b/src/source/PeerConnection/PeerConnection.c @@ -26,7 +26,7 @@ STATUS createWebRtcClientInstance() CHK_WARN(!ATOMIC_LOAD_BOOL(&pWebRtcClientContext->isContextInitialized), retStatus, "WebRtc client context already initialized, nothing to do"); CHK_ERR(!IS_VALID_MUTEX_VALUE(pWebRtcClientContext->stunCtxlock), retStatus, "Mutex seems to have been created already"); - pWebRtcClientContext->stunCtxlock = MUTEX_CREATE(FALSE); + pWebRtcClientContext->stunCtxlock = MUTEX_CREATE(TRUE); CHK_ERR(IS_VALID_MUTEX_VALUE(pWebRtcClientContext->stunCtxlock), STATUS_NULL_ARG, "Mutex creation failed"); MUTEX_LOCK(pWebRtcClientContext->stunCtxlock); locked = TRUE; @@ -825,6 +825,7 @@ PVOID resolveStunIceServerIp(PVOID args) CHAR addressResolved[KVS_IP_ADDRESS_STRING_BUFFER_LEN + 1] = {'\0'}; PCHAR pRegion; PCHAR pHostnamePostfix; + UINT64 stunDnsResolutionStartTime = 0; if (ATOMIC_LOAD_BOOL(&pWebRtcClientContext->isContextInitialized)) { MUTEX_LOCK(pWebRtcClientContext->stunCtxlock); @@ -856,6 +857,8 @@ PVOID resolveStunIceServerIp(PVOID args) } else { DLOGW("Request already received to get the URL before resolution could even start...allowing higher layers to handle resolution"); } + PROFILE_WITH_START_TIME_OBJ(stunDnsResolutionStartTime, pWebRtcClientContext->pStunIpAddrCtx->stunDnsResolutionTime, + "STUN DNS resolution time taken"); } if (locked) { MUTEX_UNLOCK(pWebRtcClientContext->stunCtxlock); @@ -1752,11 +1755,22 @@ STATUS peerConnectionGetMetrics(PRtcPeerConnection pPeerConnection, PPeerConnect { STATUS retStatus = STATUS_SUCCESS; PKvsPeerConnection pKvsPeerConnection = (PKvsPeerConnection) pPeerConnection; + PWebRtcClientContext pWebRtcClientContext = getWebRtcClientInstance(); + CHK(pKvsPeerConnection != NULL && pPeerConnectionMetrics != NULL, STATUS_NULL_ARG); if (pPeerConnectionMetrics->version > PEER_CONNECTION_METRICS_CURRENT_VERSION) { DLOGW("Peer connection metrics object version invalid..setting to highest default version %d", PEER_CONNECTION_METRICS_CURRENT_VERSION); pPeerConnectionMetrics->version = PEER_CONNECTION_METRICS_CURRENT_VERSION; } + + MUTEX_LOCK(pWebRtcClientContext->stunCtxlock); + if (pWebRtcClientContext->isContextInitialized) { + if (pWebRtcClientContext->pStunIpAddrCtx->isIpInitialized) { + pPeerConnectionMetrics->peerConnectionStats.stunDnsResolutionTime = pWebRtcClientContext->pStunIpAddrCtx->stunDnsResolutionTime; + } + } + MUTEX_UNLOCK(pWebRtcClientContext->stunCtxlock); + pPeerConnectionMetrics->peerConnectionStats.peerConnectionCreationTime = pKvsPeerConnection->peerConnectionDiagnostics.peerConnectionCreationTime; pPeerConnectionMetrics->peerConnectionStats.dtlsSessionSetupTime = pKvsPeerConnection->peerConnectionDiagnostics.dtlsSessionSetupTime; pPeerConnectionMetrics->peerConnectionStats.iceHolePunchingTime = pKvsPeerConnection->peerConnectionDiagnostics.iceHolePunchingTime; @@ -1764,6 +1778,7 @@ STATUS peerConnectionGetMetrics(PRtcPeerConnection pPeerConnection, PPeerConnect pPeerConnectionMetrics->peerConnectionStats.closePeerConnectionTime = pKvsPeerConnection->peerConnectionDiagnostics.closePeerConnectionTime; pPeerConnectionMetrics->peerConnectionStats.freePeerConnectionTime = pKvsPeerConnection->peerConnectionDiagnostics.freePeerConnectionTime; CleanUp: + releaseHoldOnInstance(pWebRtcClientContext); return retStatus; } diff --git a/src/source/PeerConnection/PeerConnection.h b/src/source/PeerConnection/PeerConnection.h index e638767055..3a47d3eebd 100644 --- a/src/source/PeerConnection/PeerConnection.h +++ b/src/source/PeerConnection/PeerConnection.h @@ -157,6 +157,7 @@ typedef struct { KvsIpAddress kvsIpAddr; BOOL isIpInitialized; UINT64 startTime; + UINT64 stunDnsResolutionTime; UINT64 expirationDuration; STATUS status; } StunIpAddrContext, *PStunIpAddrContext;