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 */
|
|
|
|
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) {
|
|
|
|
double d = (double) 1000;
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:47:0x00f7 */
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:54:0x01c9 */
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:57:0x01dc */
|
2021-10-28 06:20:59 +00:00
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:95:0x03d7 */
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:98:0x03e1 */
|
|
|
|
/* JADX WARNING: Removed duplicated region for block: B:99:0x0403 */
|
2021-08-03 07:33:18 +00:00
|
|
|
public static final Stats transform(String str) {
|
|
|
|
OutboundRtpAudio outboundRtpAudio;
|
|
|
|
long j;
|
|
|
|
Substream substream;
|
|
|
|
long j2;
|
|
|
|
OutboundRtpVideo outboundRtpVideo;
|
|
|
|
Inbound[] inbound;
|
|
|
|
long j3;
|
|
|
|
Substream[] substreams;
|
|
|
|
OutboundVideo[] videos;
|
|
|
|
OutboundAudio audio;
|
|
|
|
m.checkNotNullParameter(str, "stats");
|
2021-12-02 18:53:44 +00:00
|
|
|
NativeStats nativeStats = (NativeStats) f.v1(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());
|
|
|
|
float fractionLost = audio.getFractionLost() * ((float) 100);
|
|
|
|
float audioLevel = ((float) audio.getAudioLevel()) / 32768.0f;
|
|
|
|
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();
|
|
|
|
long longValue = noiseCancellerProcessTime != null ? noiseCancellerProcessTime.longValue() : 0;
|
|
|
|
Boolean voiceActivityDetectorIsEnabled = audio.getVoiceActivityDetectorIsEnabled();
|
|
|
|
boolean booleanValue2 = voiceActivityDetectorIsEnabled != null ? voiceActivityDetectorIsEnabled.booleanValue() : false;
|
|
|
|
Long voiceActivityDetectorProcessTime = audio.getVoiceActivityDetectorProcessTime();
|
2021-08-09 22:51:56 +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() : 0);
|
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;
|
|
|
|
int i = 0;
|
|
|
|
while (true) {
|
|
|
|
if (i >= length) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
substream = substreams[i];
|
|
|
|
if (!substream.isFlexFEC() && !substream.isRTX()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (substream == null) {
|
|
|
|
long j4 = 0;
|
|
|
|
for (Substream substream2 : outboundVideo.getSubstreams()) {
|
|
|
|
j4 += INSTANCE.sumBytes(substream2.getRtpStats());
|
|
|
|
}
|
|
|
|
long j5 = j + j4;
|
|
|
|
long ssrc2 = substream.getSsrc();
|
|
|
|
StatsCodec statsCodec2 = new StatsCodec(outboundVideo.getCodecPayloadType(), outboundVideo.getCodecName());
|
|
|
|
long j6 = 0;
|
|
|
|
for (Substream substream3 : outboundVideo.getSubstreams()) {
|
|
|
|
j6 += INSTANCE.sumPackets(substream3.getRtpStats());
|
|
|
|
}
|
2021-08-09 22:51:56 +00:00
|
|
|
outboundRtpVideo = new OutboundRtpVideo(MediaStreamTrack.VIDEO_TRACK_KIND, ssrc2, statsCodec2, j4, j6, substream.getRtcpStats().getPacketsLost(), (float) substream.getRtcpStats().getFractionLost(), outboundVideo.getMediaBitrate(), outboundVideo.getTargetMediaBitrate(), outboundVideo.getEncodeUsage(), outboundVideo.getEncoderImplementationName(), outboundVideo.getAvgEncodeTime(), new Resolution(substream.getWidth(), substream.getHeight()), (long) (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());
|
2021-08-03 07:33:18 +00:00
|
|
|
j2 = j5;
|
|
|
|
} else {
|
|
|
|
j2 = j;
|
|
|
|
outboundRtpVideo = null;
|
|
|
|
}
|
|
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
|
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap();
|
|
|
|
inbound = nativeStats.getInbound();
|
|
|
|
if (inbound == null) {
|
|
|
|
long j7 = 0;
|
|
|
|
for (Inbound inbound2 : inbound) {
|
|
|
|
String id2 = inbound2.getId();
|
|
|
|
long bytesReceived = inbound2.getAudio().getBytesReceived() + j7;
|
|
|
|
InboundAudio audio2 = inbound2.getAudio();
|
|
|
|
InboundPlayout transformPlayoutStats = inbound2.getPlayout() != null ? INSTANCE.transformPlayoutStats(inbound2.getPlayout()) : null;
|
2021-08-09 22:51:56 +00:00
|
|
|
InboundRtpAudio inboundRtpAudio = (InboundRtpAudio) linkedHashMap.put(id2, new InboundRtpAudio(MediaStreamTrack.AUDIO_TRACK_KIND, audio2.getSsrc(), new StatsCodec(audio2.getCodecPayloadType(), audio2.getCodecName()), bytesReceived, audio2.getPacketsReceived(), audio2.getPacketsLost(), ((float) 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));
|
2021-08-03 07:33:18 +00:00
|
|
|
if (inbound2.getVideo() != null) {
|
|
|
|
InboundVideo video = inbound2.getVideo();
|
|
|
|
long payloadBytes = video.getRtpStats().getPayloadBytes() + video.getRtpStats().getPaddingBytes() + video.getRtpStats().getHeaderBytes();
|
|
|
|
bytesReceived += payloadBytes;
|
2021-10-28 06:20:59 +00:00
|
|
|
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()));
|
2021-08-03 07:33:18 +00:00
|
|
|
}
|
|
|
|
j7 = bytesReceived;
|
|
|
|
}
|
|
|
|
j3 = j7;
|
|
|
|
} else {
|
|
|
|
j3 = 0;
|
|
|
|
}
|
|
|
|
Transport transport = nativeStats.getTransport();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
substream = null;
|
|
|
|
if (substream == null) {
|
|
|
|
}
|
|
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
|
|
LinkedHashMap linkedHashMap2 = new LinkedHashMap();
|
|
|
|
inbound = nativeStats.getInbound();
|
|
|
|
if (inbound == null) {
|
|
|
|
}
|
|
|
|
Transport transport = nativeStats.getTransport();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
}
|