//// MediaInfo.swift// OpenVideoCall//// Created by GongYuhua on 4/11/16.// Copyright © 2016 Agora. All rights reserved.//import Foundationimport AgoraRtcKitstruct StatisticsInfo {struct LocalInfo {var channelStats = AgoraChannelStats()var videoStats = AgoraRtcLocalVideoStats()var audioStats = AgoraRtcLocalAudioStats()}struct RemoteInfo {var videoStats = AgoraRtcRemoteVideoStats()var audioStats = AgoraRtcRemoteAudioStats()}enum StatisticsType {case local(LocalInfo), remote(RemoteInfo)var isLocal: Bool {switch self {case .local: return truecase .remote: return false}}}var dimension = CGSize.zerovar fps:UInt = 0var type: StatisticsTypeinit(type: StatisticsType) {self.type = type}mutating func updateChannelStats(_ stats: AgoraChannelStats) {guard self.type.isLocal else {return}switch type {case .local(let info):var new = infonew.channelStats = statsself.type = .local(new)default:break}}mutating func updateLocalVideoStats(_ stats: AgoraRtcLocalVideoStats) {guard self.type.isLocal else {return}switch type {case .local(let info):var new = infonew.videoStats = statsself.type = .local(new)default:break}dimension = CGSize(width: Int(stats.encodedFrameWidth), height: Int(stats.encodedFrameHeight))fps = stats.sentFrameRate}mutating func updateLocalAudioStats(_ stats: AgoraRtcLocalAudioStats) {guard self.type.isLocal else {return}switch type {case .local(let info):var new = infonew.audioStats = statsself.type = .local(new)default:break}}mutating func updateVideoStats(_ stats: AgoraRtcRemoteVideoStats) {switch type {case .remote(let info):var new = infonew.videoStats = statsdimension = CGSize(width: Int(stats.width), height: Int(stats.height))fps = stats.rendererOutputFrameRateself.type = .remote(new)default:break}}mutating func updateAudioStats(_ stats: AgoraRtcRemoteAudioStats) {switch type {case .remote(let info):var new = infonew.audioStats = statsself.type = .remote(new)default:break}}func description(audioOnly:Bool) -> String {var full: Stringswitch type {case .local(let info): full = localDescription(info: info, audioOnly: audioOnly)case .remote(let info): full = remoteDescription(info: info, audioOnly: audioOnly)}return full}func localDescription(info: LocalInfo, audioOnly: Bool) -> String {let dimensionFps = "\(Int(dimension.width))×ばつ\(Int(dimension.height)),\(fps)fps"let lastmile = "LM Delay: \(info.channelStats.lastmileDelay)ms"let videoSend = "VSend: \(info.videoStats.sentBitrate)kbps"let audioSend = "ASend: \(info.audioStats.sentBitrate)kbps"let cpu = "CPU: \(info.channelStats.cpuAppUsage)%/\(info.channelStats.cpuTotalUsage)%"let vSendLoss = "VSend Loss: \(info.videoStats.txPacketLossRate)%"let aSendLoss = "ASend Loss: \(info.audioStats.txPacketLossRate)%"if(audioOnly) {return [lastmile,audioSend,cpu,aSendLoss].joined(separator: "\n")}return [dimensionFps,lastmile,videoSend,audioSend,cpu,vSendLoss,aSendLoss].joined(separator: "\n")}func remoteDescription(info: RemoteInfo, audioOnly: Bool) -> String {let dimensionFpsBit = "\(Int(dimension.width))×ばつ\(Int(dimension.height)), \(fps)fps"var audioQuality: AgoraNetworkQualityif let quality = AgoraNetworkQuality(rawValue: info.audioStats.quality) {audioQuality = quality} else {audioQuality = AgoraNetworkQuality.unknown}let videoRecv = "VRecv: \(info.videoStats.receivedBitrate)kbps"let audioRecv = "ARecv: \(info.audioStats.receivedBitrate)kbps"let videoLoss = "VLoss: \(info.videoStats.packetLossRate)%"let audioLoss = "ALoss: \(info.audioStats.audioLossRate)%"let aquality = "AQuality: \(audioQuality.description())"if(audioOnly) {return [audioRecv,audioLoss,aquality].joined(separator: "\n")}return [dimensionFpsBit,videoRecv,audioRecv,videoLoss,audioLoss,aquality].joined(separator: "\n")}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。