IEnumerator LoopGetStats() { while (true) { yield return(new WaitForSeconds(1f)); if (!sendButton.interactable) { continue; } var op1 = pc1.GetStats(); var op2 = pc2.GetStats(); yield return(op1); yield return(op2); Debug.Log("pc1"); foreach (var stat in op1.Value.Stats.Values) { Debug.Log(stat.Type.ToString()); } Debug.Log("pc2"); foreach (var stat in op2.Value.Stats.Values) { Debug.Log(stat.Type.ToString()); } } }
IEnumerator LoopGetStats() { while (true) { yield return(new WaitForSeconds(1f)); if (callButton.interactable) { continue; } var op1 = pc1.GetStats(); var op2 = pc2.GetStats(); yield return(op1); yield return(op2); if (op1.IsError || op2.IsError) { continue; } if (dropdown.options.Count == 0) { List <string> options = new List <string>(); foreach (var stat in op1.Value.Stats.Keys) { options.Add($"{stat}"); } dropdown.ClearOptions(); dropdown.AddOptions(options); dropdown.interactable = true; } if (currentValue != dropdown.value) { currentValue = dropdown.value; } var id = dropdown.options[currentValue].text; text.text = "Id:" + op1.Value.Stats[id].Id + "\n"; text.text += "Timestamp:" + op1.Value.Stats[id].Timestamp + "\n"; text.interactable = true; if (!op1.Value.TryGetValue(id, out RTCStats stats)) { continue; } text.text += stats.Dict.Aggregate(string.Empty, (str, next) => str + next.Key + ":" + (next.Value == null ? string.Empty : next.Value.ToString()) + "\n"); } }
// 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; }
// 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 ); }
IEnumerator LoopGetStats() { while (true) { yield return(new WaitForSeconds(1f)); if (callButton.interactable) { continue; } var op1 = pc1.GetStats(); var op2 = pc2.GetStats(); yield return(op1); yield return(op2); if (op1.IsError || op2.IsError) { continue; } if (dropdown.options.Count == 0) { List <string> options = new List <string>(); foreach (var stat in op1.Value.Stats.Keys) { options.Add($"{stat.Item1}-{stat.Item2}"); } dropdown.ClearOptions(); dropdown.AddOptions(options); } if (currentValue != dropdown.value) { currentValue = dropdown.value; } var currentOption = dropdown.options[currentValue].text.Split('-'); var type = (RTCStatsType)Enum.Parse(typeof(RTCStatsType), currentOption[0]); var id = currentOption[1]; text.text = "Id:" + op1.Value.Stats[(type, id)].Id + "\n";
// 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 ); }
public static async Task GetAllStats(RTCPeerConnection pc) { IRTCStatsReport statsReport = await Task.Run(async() => await pc.GetStats(statsType)); GetAllStatsData(statsReport); }