Skip to content

Commit

Permalink
Merge 0451653 into 3ba7c05
Browse files Browse the repository at this point in the history
  • Loading branch information
disa6302 authored Oct 16, 2023
2 parents 3ba7c05 + 0451653 commit 79f766c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
17 changes: 16 additions & 1 deletion src/source/PeerConnection/PeerConnection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1752,18 +1755,30 @@ 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;
// Cannot record these 2 in here because peer connection object would become NULL after clearing. Need another strategy
pPeerConnectionMetrics->peerConnectionStats.closePeerConnectionTime = pKvsPeerConnection->peerConnectionDiagnostics.closePeerConnectionTime;
pPeerConnectionMetrics->peerConnectionStats.freePeerConnectionTime = pKvsPeerConnection->peerConnectionDiagnostics.freePeerConnectionTime;
CleanUp:
releaseHoldOnInstance(pWebRtcClientContext);
return retStatus;
}

Expand Down
1 change: 1 addition & 0 deletions src/source/PeerConnection/PeerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ typedef struct {
KvsIpAddress kvsIpAddr;
BOOL isIpInitialized;
UINT64 startTime;
UINT64 stunDnsResolutionTime;
UINT64 expirationDuration;
STATUS status;
} StunIpAddrContext, *PStunIpAddrContext;
Expand Down

0 comments on commit 79f766c

Please sign in to comment.