2021-08-03 07:33:18 +00:00
|
|
|
package co.discord.media_engine.internal;
|
|
|
|
|
2021-12-17 21:59:34 +00:00
|
|
|
import b.i.a.f.e.o.f;
|
2021-08-03 07:33:18 +00:00
|
|
|
import co.discord.media_engine.InboundRtpAudio;
|
|
|
|
import co.discord.media_engine.InboundRtpVideo;
|
|
|
|
import co.discord.media_engine.OutboundRtpAudio;
|
|
|
|
import co.discord.media_engine.OutboundRtpVideo;
|
|
|
|
import co.discord.media_engine.PlayoutMetric;
|
|
|
|
import co.discord.media_engine.Resolution;
|
|
|
|
import co.discord.media_engine.Stats;
|
|
|
|
import co.discord.media_engine.StatsCodec;
|
|
|
|
import co.discord.media_engine.Transport;
|
|
|
|
import com.google.gson.Gson;
|
2021-11-02 06:38:17 +00:00
|
|
|
import d0.t.k;
|
|
|
|
import d0.z.d.m;
|
2021-08-03 07:33:18 +00:00
|
|
|
import java.util.LinkedHashMap;
|
2021-08-09 22:51:56 +00:00
|
|
|
import org.webrtc.MediaStreamTrack;
|
2021-08-03 07:33:18 +00:00
|
|
|
/* compiled from: TransformStats.kt */
|
2022-03-07 09:34:54 +00:00
|
|
|
/* loaded from: classes.dex */
|
2021-08-03 07:33:18 +00:00
|
|
|
public final class TransformStats {
|
|
|
|
public static final TransformStats INSTANCE = new TransformStats();
|
|
|
|
private static final Gson gson = new Gson();
|
|
|
|
|
|
|
|
private TransformStats() {
|
|
|
|
}
|
|
|
|
|
|
|
|
private final PlayoutMetric convertPlayoutMetricToMs(PlayoutMetric playoutMetric) {
|
2022-03-07 09:34:54 +00:00
|
|
|
double d = 1000;
|
2021-08-03 07:33:18 +00:00
|
|
|
return new PlayoutMetric(Math.rint(playoutMetric.getLast() * d), Math.rint(playoutMetric.getMean() * d), Math.rint(playoutMetric.getP75() * d), Math.rint(playoutMetric.getP95() * d), Math.rint(playoutMetric.getP99() * d), Math.rint(playoutMetric.getMax() * d));
|
|
|
|
}
|
|
|
|
|
|
|
|
private final long sumBytes(RtpStats rtpStats) {
|
|
|
|
return rtpStats.getTransmitted().getPaddingBytes() + rtpStats.getTransmitted().getPayloadBytes() + rtpStats.getTransmitted().getHeaderBytes() + rtpStats.getRetransmitted().getPaddingBytes() + rtpStats.getRetransmitted().getPayloadBytes() + rtpStats.getRetransmitted().getHeaderBytes() + rtpStats.getFec().getPaddingBytes() + rtpStats.getFec().getPayloadBytes() + rtpStats.getFec().getHeaderBytes();
|
|
|
|
}
|
|
|
|
|
|
|
|
private final long sumPackets(RtpStats rtpStats) {
|
|
|
|
return rtpStats.getTransmitted().getPackets() + rtpStats.getRetransmitted().getPackets() + rtpStats.getFec().getPackets();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final Stats transform(String str) {
|
|
|
|
OutboundRtpAudio outboundRtpAudio;
|
|
|
|
long j;
|
|
|
|
Substream substream;
|
|
|
|
long j2;
|
|
|
|
OutboundRtpVideo outboundRtpVideo;
|
|
|
|
long j3;
|
|
|
|
Substream[] substreams;
|
|
|
|
OutboundVideo[] videos;
|
|
|
|
OutboundAudio audio;
|
|
|
|
m.checkNotNullParameter(str, "stats");
|
2022-01-13 08:07:50 +00:00
|
|
|
NativeStats nativeStats = (NativeStats) f.E1(NativeStats.class).cast(gson.g(str, NativeStats.class));
|
2021-08-03 07:33:18 +00:00
|
|
|
Outbound outbound = nativeStats.getOutbound();
|
|
|
|
if (outbound == null || (audio = outbound.getAudio()) == null) {
|
|
|
|
j = 0;
|
|
|
|
outboundRtpAudio = null;
|
|
|
|
} else {
|
|
|
|
j = audio.getBytesSent() + 0;
|
|
|
|
long ssrc = audio.getSsrc();
|
|
|
|
StatsCodec statsCodec = new StatsCodec(audio.getCodecPayloadType(), audio.getCodecName());
|
|
|
|
long packetsSent = audio.getPacketsSent();
|
|
|
|
int max = Math.max(0, audio.getPacketsLost());
|
2022-03-07 09:34:54 +00:00
|
|
|
float fractionLost = audio.getFractionLost() * 100;
|
|
|
|
float audioLevel = audio.getAudioLevel() / 32768.0f;
|
2021-08-03 07:33:18 +00:00
|
|
|
boolean z2 = audio.getSpeaking() > 0;
|
|
|
|
long framesCaptured = audio.getFramesCaptured();
|
|
|
|
long framesRendered = audio.getFramesRendered();
|
|
|
|
Boolean noiseCancellerIsEnabled = audio.getNoiseCancellerIsEnabled();
|
|
|
|
boolean booleanValue = noiseCancellerIsEnabled != null ? noiseCancellerIsEnabled.booleanValue() : false;
|
|
|
|
Long noiseCancellerProcessTime = audio.getNoiseCancellerProcessTime();
|
2022-03-07 09:34:54 +00:00
|
|
|
long longValue = noiseCancellerProcessTime != null ? noiseCancellerProcessTime.longValue() : 0L;
|
2021-08-03 07:33:18 +00:00
|
|
|
Boolean voiceActivityDetectorIsEnabled = audio.getVoiceActivityDetectorIsEnabled();
|
|
|
|
boolean booleanValue2 = voiceActivityDetectorIsEnabled != null ? voiceActivityDetectorIsEnabled.booleanValue() : false;
|
|
|
|
Long voiceActivityDetectorProcessTime = audio.getVoiceActivityDetectorProcessTime();
|
2022-03-07 09:34:54 +00:00
|
|
|
outboundRtpAudio = new OutboundRtpAudio(MediaStreamTrack.AUDIO_TRACK_KIND, ssrc, statsCodec, j, packetsSent, max, fractionLost, audioLevel, z2, framesCaptured, framesRendered, booleanValue, longValue, booleanValue2, voiceActivityDetectorProcessTime != null ? voiceActivityDetectorProcessTime.longValue() : 0L);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
Outbound outbound2 = nativeStats.getOutbound();
|
|
|
|
OutboundVideo outboundVideo = (outbound2 == null || (videos = outbound2.getVideos()) == null) ? null : (OutboundVideo) k.firstOrNull(videos);
|
|
|
|
if (!(outboundVideo == null || (substreams = outboundVideo.getSubstreams()) == null)) {
|
|
|
|
int length = substreams.length;
|
2022-03-07 09:34:54 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2021-08-03 07:33:18 +00:00
|
|
|
substream = substreams[i];
|
|
|
|
if (!substream.isFlexFEC() && !substream.isRTX()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
substream = null;
|
2022-03-07 09:34:54 +00:00
|
|
|
if (substream != null) {
|
|
|
|
long j4 = 0;
|
|
|
|
for (Substream substream2 : outboundVideo.getSubstreams()) {
|
|
|
|
j4 += INSTANCE.sumBytes(substream2.getRtpStats());
|
|
|
|
}
|
|
|
|
j2 = j + j4;
|
|
|
|
long ssrc2 = substream.getSsrc();
|
|
|
|
StatsCodec statsCodec2 = new StatsCodec(outboundVideo.getCodecPayloadType(), outboundVideo.getCodecName());
|
|
|
|
long j5 = 0;
|
|
|
|
for (Substream substream3 : outboundVideo.getSubstreams()) {
|
|
|
|
j5 += INSTANCE.sumPackets(substream3.getRtpStats());
|
|
|
|
}
|
|
|
|
outboundRtpVideo = new OutboundRtpVideo(MediaStreamTrack.VIDEO_TRACK_KIND, ssrc2, statsCodec2, j4, j5, substream.getRtcpStats().getPacketsLost(), substream.getRtcpStats().getFractionLost(), outboundVideo.getMediaBitrate(), outboundVideo.getTargetMediaBitrate(), outboundVideo.getEncodeUsage(), outboundVideo.getEncoderImplementationName(), outboundVideo.getAvgEncodeTime(), new Resolution(substream.getWidth(), substream.getHeight()), substream.getFrameCounts().getKeyFrames() + substream.getFrameCounts().getDeltaFrames(), outboundVideo.getFramesEncoded(), outboundVideo.getInputFrameRate(), outboundVideo.getEncodeFrameRate(), substream.getRtcpStats().getFirPackets(), substream.getRtcpStats().getNackPackets(), substream.getRtcpStats().getPliPackets(), outboundVideo.getQpSum(), outboundVideo.getBwLimitedResolution(), outboundVideo.getCpuLimitedResolution());
|
|
|
|
} else {
|
|
|
|
j2 = j;
|
|
|
|
outboundRtpVideo = null;
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
|
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap();
|
2022-03-07 09:34:54 +00:00
|
|
|
Inbound[] inbound = nativeStats.getInbound();
|
|
|
|
if (inbound != null) {
|
|
|
|
long j6 = 0;
|
|
|
|
for (Inbound inbound2 : inbound) {
|
|
|
|
String id2 = inbound2.getId();
|
|
|
|
j6 = inbound2.getAudio().getBytesReceived() + j6;
|
|
|
|
InboundAudio audio2 = inbound2.getAudio();
|
|
|
|
InboundPlayout transformPlayoutStats = inbound2.getPlayout() != null ? INSTANCE.transformPlayoutStats(inbound2.getPlayout()) : null;
|
|
|
|
InboundRtpAudio inboundRtpAudio = (InboundRtpAudio) linkedHashMap.put(id2, new InboundRtpAudio(MediaStreamTrack.AUDIO_TRACK_KIND, audio2.getSsrc(), new StatsCodec(audio2.getCodecPayloadType(), audio2.getCodecName()), j6, audio2.getPacketsReceived(), audio2.getPacketsLost(), audio2.getAudioLevel() / 32768.0f, audio2.getSpeaking() > 0, audio2.getJitter(), audio2.getJitterBuffer(), audio2.getJitterBufferPreferred(), audio2.getDelayEstimate(), audio2.getDecodingCNG(), audio2.getDecodingMutedOutput(), audio2.getDecodingNormal(), audio2.getDecodingPLC(), audio2.getDecodingPLCCNG(), Long.valueOf(audio2.getOpSilence()), Long.valueOf(audio2.getOpNormal()), Long.valueOf(audio2.getOpMerge()), Long.valueOf(audio2.getOpExpand()), Long.valueOf(audio2.getOpAccelerate()), Long.valueOf(audio2.getOpPreemptiveExpand()), Long.valueOf(audio2.getOpCNG()), transformPlayoutStats != null ? transformPlayoutStats.getAudioJitterBuffer() : null, transformPlayoutStats != null ? transformPlayoutStats.getAudioJitterDelay() : null, transformPlayoutStats != null ? transformPlayoutStats.getAudioJitterTarget() : null, transformPlayoutStats != null ? transformPlayoutStats.getAudioPlayoutUnderruns() : null, transformPlayoutStats != null ? transformPlayoutStats.getRelativeReceptionDelay() : null, transformPlayoutStats != null ? transformPlayoutStats.getRelativePlayoutDelay() : null));
|
|
|
|
if (inbound2.getVideo() != null) {
|
|
|
|
InboundVideo video = inbound2.getVideo();
|
|
|
|
long payloadBytes = video.getRtpStats().getPayloadBytes() + video.getRtpStats().getPaddingBytes() + video.getRtpStats().getHeaderBytes();
|
|
|
|
j6 += payloadBytes;
|
|
|
|
InboundRtpVideo inboundRtpVideo = (InboundRtpVideo) linkedHashMap2.put(id2, new InboundRtpVideo(MediaStreamTrack.VIDEO_TRACK_KIND, video.getSsrc(), video.getCodecPayloadType() != -1 ? new StatsCodec(video.getCodecPayloadType(), video.getCodecName()) : null, payloadBytes, (int) video.getRtpStats().getPackets(), video.getRtpStats().getPacketsLost(), video.getTotalBitrate(), video.getDecode(), new Resolution(video.getWidth(), video.getHeight()), video.getDecoderImplementationName(), (int) video.getFramesDecoded(), video.getFramesDropped(), video.getFrameCounts().getKeyFrames() + video.getFrameCounts().getDeltaFrames(), video.getDecodeFrameRate(), video.getNetworkFrameRate(), video.getRenderFrameRate(), video.getRtcpStats().getFirPackets(), video.getRtcpStats().getNackPackets(), video.getRtcpStats().getPliPackets(), video.getQpSum(), video.getFreezeCount(), video.getPauseCount(), video.getTotalFreezesDuration(), video.getTotalPausesDuration(), video.getTotalFramesDuration(), video.getSumOfSquaredFramesDurations()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
j3 = j6;
|
|
|
|
} else {
|
|
|
|
j3 = 0;
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
Transport transport = nativeStats.getTransport();
|
2022-03-07 09:34:54 +00:00
|
|
|
return new Stats(transport != null ? new Transport(transport.getSendBandwidth(), j3, j2, transport.getRtt(), Integer.valueOf((int) transport.getDecryptionFailures()), transport.getLocalAddress(), transport.getReceiverReports()) : new Transport(0, j3, j2, 0, 0, "", null), outboundRtpAudio, outboundRtpVideo, linkedHashMap, linkedHashMap2);
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private final InboundPlayout transformPlayoutStats(InboundPlayout inboundPlayout) {
|
|
|
|
return new InboundPlayout(convertPlayoutMetricToMs(inboundPlayout.getAudioJitterBuffer()), convertPlayoutMetricToMs(inboundPlayout.getAudioJitterDelay()), convertPlayoutMetricToMs(inboundPlayout.getAudioJitterTarget()), convertPlayoutMetricToMs(inboundPlayout.getAudioPlayoutUnderruns()), convertPlayoutMetricToMs(inboundPlayout.getAudioCaptureOverruns()), convertPlayoutMetricToMs(inboundPlayout.getVideoJitterBuffer()), convertPlayoutMetricToMs(inboundPlayout.getVideoJitterDelay()), convertPlayoutMetricToMs(inboundPlayout.getVideoJitterTarget()), convertPlayoutMetricToMs(inboundPlayout.getRelativeReceptionDelay()), convertPlayoutMetricToMs(inboundPlayout.getRelativePlayoutDelay()));
|
|
|
|
}
|
|
|
|
}
|