private void UpdateStatsPacketSize(RTCStatsReport res) { foreach (RTCStats stats in res.Stats.Values) { if (!(stats is RTCOutboundRTPStreamStats report)) { continue; } long now = report.Timestamp; ulong bytes = report.bytesSent; if (lastResult != null) { if (!lastResult.TryGetValue(report.Id, out RTCStats last)) { continue; } var lastStats = last as RTCOutboundRTPStreamStats; var duration = (double)(now - lastStats.Timestamp) / 1000000; ulong bitrate = (ulong)(8 * (bytes - lastStats.bytesSent) / duration); statsField.text += $"Bitrate: {bitrate}" + Environment.NewLine; if (autoScroll.isOn) { statsField.MoveTextEnd(false); } } } lastResult = res; }
private void UpdateStatsPacketSize(RTCStatsReport res) { foreach (RTCStats stats in res.Stats.Values) { if (!(stats is RTCOutboundRTPStreamStats report)) { continue; } long now = report.Timestamp; ulong bytes = report.bytesSent; if (lastResult != null) { if (!lastResult.TryGetValue(report.Id, out RTCStats last)) { continue; } var lastStats = last as RTCOutboundRTPStreamStats; var duration = (double)(now - lastStats.Timestamp) / 1000000; ulong bitrate = (ulong)(8 * (bytes - lastStats.bytesSent) / duration); textBandwidth.text = (bitrate / 1000.0f).ToString("f2"); //if (autoScroll.isOn) //{ // statsField.MoveTextEnd(false); //} } } lastResult = res; }
internal RTCStatsReportAsyncOperation(RTCPeerConnection connection, RTCRtpReceiver receiver) { NativeMethods.PeerConnectionReceiverGetStats(connection.GetSelfOrThrow(), receiver.self); connection.OnStatsDelivered = ptr => { Value = WebRTC.FindOrCreate(ptr, ptr_ => new RTCStatsReport(ptr_)); IsError = false; this.Done(); }; }
internal RTCStatsReportAsyncOperation(RTCPeerConnection connection, RTCRtpReceiver receiver) { NativeMethods.PeerConnectionReceiverGetStats(connection.self, receiver.self); connection.OnStatsDelivered = ptr => { Value = new RTCStatsReport(ptr); IsError = false; this.Done(); }; }
// Display the video codec that is actually used. IEnumerator CheckStats(RTCPeerConnection pc) { yield return(new WaitForSeconds(0.1f)); if (pc == null) { yield break; } var op = pc.GetStats(); yield return(op); if (op.IsError) { Debug.LogErrorFormat("RTCPeerConnection.GetStats failed: {0}", op.Error); yield break; } RTCStatsReport report = op.Value; RTCIceCandidatePairStats activeCandidatePairStats = null; RTCIceCandidateStats remoteCandidateStats = null; foreach (var transportStatus in report.Stats.Values.OfType <RTCTransportStats>()) { if (report.Stats.TryGetValue(transportStatus.selectedCandidatePairId, out var tmp)) { activeCandidatePairStats = tmp as RTCIceCandidatePairStats; } } if (activeCandidatePairStats == null || string.IsNullOrEmpty(activeCandidatePairStats.remoteCandidateId)) { yield break; } foreach (var iceCandidateStatus in report.Stats.Values.OfType <RTCIceCandidateStats>()) { if (iceCandidateStatus.Id == activeCandidatePairStats.remoteCandidateId) { remoteCandidateStats = iceCandidateStatus; } } if (remoteCandidateStats == null || string.IsNullOrEmpty(remoteCandidateStats.Id)) { yield break; } Debug.Log($"{GetName(pc)} candidate stats Id:{remoteCandidateStats.Id}, Type:{remoteCandidateStats.candidateType}"); var updateText = GetName(pc) == "pc1" ? localCandidateId : remoteCandidateId; updateText.text = remoteCandidateStats.Id; }
internal RTCStatsReportAsyncOperation(RTCPeerConnection connection, RTCRtpSender sender) { NativeMethods.PeerConnectionSenderGetStats(connection.GetSelfOrThrow(), sender.self); connection.OnStatsDelivered = ptr => { Value = new RTCStatsReport(ptr); IsError = false; this.Done(); }; }
public void Update(RTCStatsReport report) { foreach (var element in report.Stats) { if (!m_statsRecordMap.ContainsKey(element.Key)) { m_statsRecordMap[element.Key] = new StatsRecord(element.Value.Id); } m_statsRecordMap[element.Key].Update(element.Value.Timestamp, element.Value.Dict); } }
// Display the video codec that is actually used. IEnumerator CheckActualCodec() { yield return(new WaitForSeconds(1f)); var op = _pc1.GetStats(); yield return(op); if (op.IsError) { Debug.LogErrorFormat("RTCPeerConnection.GetStats failed: {0}", op.Error); yield break; } RTCStatsReport report = op.Value; IEnumerable <RTCOutboundRTPStreamStats> outBoundStatsList = report.Stats.Values.Where( stats => stats.Type == RTCStatsType.OutboundRtp).Cast <RTCOutboundRTPStreamStats>(); RTCOutboundRTPStreamStats outBoundStats = outBoundStatsList.First(stats => stats.kind == "video"); string codecId = outBoundStats.codecId; IEnumerable <RTCCodecStats> codecStatsList = report.Stats.Values.Where( stats => stats.Type == RTCStatsType.Codec).Cast <RTCCodecStats>(); RTCCodecStats codecStats = codecStatsList.First(stats => stats.Id == codecId); var arr = outBoundStatsList.ToArray(); var arr2 = codecStatsList.ToArray(); Debug.Log(arr); Debug.Log(arr2); //foreach (var s in report.Stats.Values.Where(stats => stats is RTCCodecStats)) //{ // var s2 = s as RTCCodecStats; // Debug.Log(s2.Type + " " + s2.Id); //} actualCodecText.text = string.Format("Using {0} {1}, payloadType={2}.", codecStats.mimeType, codecStats.sdpFmtpLine, codecStats.payloadType ); }
private async void CollectCallMetrics3(object state) { CallDuration += ScheduleTimeInSeconds; StatsData statsData = CallsStatsDictionary[_currentId]; statsData.Timestamps.Add(CallDuration); RTCStatsReport report = await StatsProviderPeerConnectionCall.GetStats(); if (report != null) { foreach (var statId in report.StatsIds) { RTCStats stats = report.GetStats(statId); if (IsStatsCollectionEnabled) { ParseStats(stats, statsData); } else { UpdateCurrentFrame(stats); } } } }
// Display the video codec that is actually used. IEnumerator CheckActualCodec() { yield return(new WaitForSeconds(1f)); if (_pc1 == null) { yield break; } var op = _pc1.GetStats(); yield return(op); if (op.IsError) { Debug.LogErrorFormat("RTCPeerConnection.GetStats failed: {0}", op.Error); yield break; } RTCStatsReport report = op.Value; List <RTCOutboundRTPStreamStats> outBoundStatsList = report.Stats.Values.Where( stats => stats.Type == RTCStatsType.OutboundRtp).Cast <RTCOutboundRTPStreamStats>().ToList(); if (!outBoundStatsList.Any()) { Debug.LogWarning($"{nameof(RTCStatsReport)} don't contain any {nameof(RTCOutboundRTPStreamStats)}"); yield break; } RTCOutboundRTPStreamStats outBoundStats = outBoundStatsList.FirstOrDefault(stats => stats.kind == "video"); if (outBoundStats == null) { Debug.LogWarning($"{nameof(RTCOutboundRTPStreamStats)} with kind video is not included in {nameof(outBoundStatsList)}."); yield break; } string codecId = outBoundStats.codecId; List <RTCCodecStats> codecStatsList = report.Stats.Values.Where( stats => stats.Type == RTCStatsType.Codec).Cast <RTCCodecStats>().ToList(); if (!codecStatsList.Any()) { Debug.LogWarning($"{nameof(RTCOutboundRTPStreamStats)} don't contain any {nameof(RTCCodecStats)}"); yield break; } RTCCodecStats codecStats = codecStatsList.FirstOrDefault(stats => stats.Id == codecId); if (codecStats == null) { Debug.LogWarning($"{nameof(RTCCodecStats)} with codecId {codecId} is not included in {nameof(codecStatsList)}."); yield break; } actualCodecText.text = string.Format("Using {0} {1}, payloadType={2}.", codecStats.mimeType, codecStats.sdpFmtpLine, codecStats.payloadType ); }