|
61 | 61 | #include "llrand.h" |
62 | 62 | #include "llviewerwindow.h" |
63 | 63 | #include "llviewercamera.h" |
| 64 | +#include "llviewerstats.h" |
64 | 65 | #include "llversioninfo.h" |
65 | 66 |
|
66 | 67 | #include "llviewernetwork.h" |
|
81 | 82 |
|
82 | 83 | const std::string WEBRTC_VOICE_SERVER_TYPE = "webrtc"; |
83 | 84 |
|
| 85 | +const F32 STATS_TIMER_DELAY = 2.0; |
| 86 | + |
84 | 87 | namespace { |
85 | 88 |
|
86 | 89 | const F32 MAX_AUDIO_DIST = 50.0f; |
@@ -2905,6 +2908,7 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() |
2905 | 2908 | } |
2906 | 2909 | mWebRTCAudioInterface->setReceiveVolume(mSpeakerVolume); |
2907 | 2910 | LLWebRTCVoiceClient::getInstance()->OnConnectionEstablished(mChannelID, mRegionID); |
| 2911 | + resetConnectionStats(); |
2908 | 2912 | setVoiceConnectionState(VOICE_STATE_WAIT_FOR_DATA_CHANNEL); |
2909 | 2913 | break; |
2910 | 2914 | } |
@@ -2954,6 +2958,13 @@ bool LLVoiceWebRTCConnection::connectionStateMachine() |
2954 | 2958 | sendJoin(); |
2955 | 2959 | } |
2956 | 2960 | } |
| 2961 | + |
| 2962 | + static LLTimer stats_timer; |
| 2963 | + if (stats_timer.getElapsedTimeF32() > STATS_TIMER_DELAY) |
| 2964 | + { |
| 2965 | + mWebRTCPeerConnectionInterface->gatherConnectionStats(); |
| 2966 | + stats_timer.reset(); |
| 2967 | + } |
2957 | 2968 | } |
2958 | 2969 | break; |
2959 | 2970 | } |
@@ -3288,6 +3299,112 @@ void LLVoiceWebRTCConnection::sendJoin() |
3288 | 3299 | mWebRTCDataInterface->sendData(json_data, false); |
3289 | 3300 | } |
3290 | 3301 |
|
| 3302 | +void LLVoiceWebRTCConnection::OnStatsDelivered(const llwebrtc::LLWebRTCStatsMap& stats_data) |
| 3303 | +{ |
| 3304 | + LL::WorkQueue::postMaybe(mMainQueue, [=, this] |
| 3305 | + { |
| 3306 | + if (mShutDown) |
| 3307 | + { |
| 3308 | + return; |
| 3309 | + } |
| 3310 | + for (const auto& [stats_id, attributes] : stats_data) |
| 3311 | + { |
| 3312 | + if (attributes.contains("currentRoundTripTime")) |
| 3313 | + { |
| 3314 | + F32 rtt_seconds = 0.0f; |
| 3315 | + LLStringUtil::convertToF32(attributes.at("currentRoundTripTime"), rtt_seconds); |
| 3316 | + sample(LLStatViewer::WEBRTC_LATENCY, rtt_seconds * 1000.0f); |
| 3317 | + } |
| 3318 | + if (attributes.contains("availableOutgoingBitrate")) |
| 3319 | + { |
| 3320 | + F32 bitrate_bps = 0.0f; |
| 3321 | + LLStringUtil::convertToF32(attributes.at("availableOutgoingBitrate"), bitrate_bps); |
| 3322 | + sample(LLStatViewer::WEBRTC_UPLOAD_BANDWIDTH, bitrate_bps / 1000.0f); |
| 3323 | + } |
| 3324 | + |
| 3325 | + // Stat type detection below is heuristic-based. |
| 3326 | + // It's relied on specific fields to distinguish outbound-rtp, remote-inbound-rtp, and inbound-rtp. |
| 3327 | + // This approach works with current WebRTC stats but may need updating later. |
| 3328 | + |
| 3329 | + // Outbound RTP |
| 3330 | + if (attributes.contains("mediaSourceId")) |
| 3331 | + { |
| 3332 | + U32 out_packets_sent = 0; |
| 3333 | + LLStringUtil::convertToU32(attributes.at("packetsSent"), out_packets_sent); |
| 3334 | + sample(LLStatViewer::WEBRTC_PACKETS_OUT_SENT, out_packets_sent); |
| 3335 | + } |
| 3336 | + // Remote-Inbound RTP |
| 3337 | + else if (attributes.contains("localId")) |
| 3338 | + { |
| 3339 | + if (attributes.contains("packetsLost")) |
| 3340 | + { |
| 3341 | + U32 out_packets_lost = 0; |
| 3342 | + LLStringUtil::convertToU32(attributes.at("packetsLost"), out_packets_lost); |
| 3343 | + sample(LLStatViewer::WEBRTC_PACKETS_OUT_LOST, out_packets_lost); |
| 3344 | + } |
| 3345 | + if (attributes.contains("jitter")) |
| 3346 | + { |
| 3347 | + F32 jitter_seconds = 0.0f; |
| 3348 | + LLStringUtil::convertToF32(attributes.at("jitter"), jitter_seconds); |
| 3349 | + sample(LLStatViewer::WEBRTC_JITTER_OUT, jitter_seconds * 1000.0f); |
| 3350 | + } |
| 3351 | + } |
| 3352 | + // Inbound RTP |
| 3353 | + else if (attributes.contains("jitterBufferDelay")) |
| 3354 | + { |
| 3355 | + if (attributes.contains("packetsLost")) |
| 3356 | + { |
| 3357 | + U32 in_packets_lost = 0; |
| 3358 | + LLStringUtil::convertToU32(attributes.at("packetsLost"), in_packets_lost); |
| 3359 | + sample(LLStatViewer::WEBRTC_PACKETS_IN_LOST, in_packets_lost); |
| 3360 | + } |
| 3361 | + if (attributes.contains("packetsReceived")) |
| 3362 | + { |
| 3363 | + U32 in_packets_recv = 0; |
| 3364 | + LLStringUtil::convertToU32(attributes.at("packetsReceived"), in_packets_recv); |
| 3365 | + sample(LLStatViewer::WEBRTC_PACKETS_IN_RECEIVED, in_packets_recv); |
| 3366 | + } |
| 3367 | + if (attributes.contains("jitter")) |
| 3368 | + { |
| 3369 | + F32 jitter_seconds = 0.0f; |
| 3370 | + LLStringUtil::convertToF32(attributes.at("jitter"), jitter_seconds); |
| 3371 | + sample(LLStatViewer::WEBRTC_JITTER_IN, jitter_seconds * 1000.0f); |
| 3372 | + } |
| 3373 | + if (attributes.contains("jitterBufferDelay") && attributes.contains("jitterBufferEmittedCount")) |
| 3374 | + { |
| 3375 | + F32 total_delay_seconds = 0.0f; |
| 3376 | + F32 emitted_count_f = 0.0f; |
| 3377 | + |
| 3378 | + // total delay in seconds |
| 3379 | + LLStringUtil::convertToF32(attributes.at("jitterBufferDelay"), total_delay_seconds); |
| 3380 | + |
| 3381 | + // number of packets played out |
| 3382 | + LLStringUtil::convertToF32(attributes.at("jitterBufferEmittedCount"), emitted_count_f); |
| 3383 | + if (emitted_count_f > 0.0f) |
| 3384 | + { |
| 3385 | + F32 avg_delay_seconds = total_delay_seconds / emitted_count_f; |
| 3386 | + F32 avg_delay_ms = avg_delay_seconds * 1000.0f; |
| 3387 | + sample(LLStatViewer::WEBRTC_JITTER_BUFFER, avg_delay_seconds * 1000.0f); |
| 3388 | + } |
| 3389 | + } |
| 3390 | + } |
| 3391 | + } |
| 3392 | + }); |
| 3393 | +} |
| 3394 | + |
| 3395 | +void LLVoiceWebRTCConnection::resetConnectionStats() |
| 3396 | +{ |
| 3397 | + sample(LLStatViewer::WEBRTC_JITTER_BUFFER, 0); |
| 3398 | + sample(LLStatViewer::WEBRTC_JITTER_IN, 0); |
| 3399 | + sample(LLStatViewer::WEBRTC_JITTER_OUT, 0); |
| 3400 | + sample(LLStatViewer::WEBRTC_LATENCY, 0); |
| 3401 | + sample(LLStatViewer::WEBRTC_PACKETS_IN_LOST, 0); |
| 3402 | + sample(LLStatViewer::WEBRTC_PACKETS_IN_RECEIVED, 0); |
| 3403 | + sample(LLStatViewer::WEBRTC_PACKETS_OUT_SENT, 0); |
| 3404 | + sample(LLStatViewer::WEBRTC_PACKETS_OUT_LOST, 0); |
| 3405 | + sample(LLStatViewer::WEBRTC_UPLOAD_BANDWIDTH, 0); |
| 3406 | +} |
| 3407 | + |
3291 | 3408 | ///////////////////////////// |
3292 | 3409 | // WebRTC Spatial Connection |
3293 | 3410 |
|
|
0 commit comments