discord-jadx/app/src/main/java/co/discord/media_engine/VoiceQuality.java

245 lines
12 KiB
Java

package co.discord.media_engine;
import d0.z.d.m;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
/* compiled from: VoiceQuality.kt */
public final class VoiceQuality {
private Duration _duration = new Duration(0, 0, 0, 0);
private Map<String, InboundAudio> _inboundStats = new LinkedHashMap();
private OutboundAudio _outboundStats = new OutboundAudio(0, 0);
public final void getBufferStats(Map<String, Object> map) {
PlayoutMetric audioJitterBuffer;
m.checkNotNullParameter(map, "result");
PlayoutMetric playoutMetric = null;
InboundBufferStats inboundBufferStats = null;
for (Map.Entry<String, InboundAudio> entry : this._inboundStats.entrySet()) {
InboundAudio value = entry.getValue();
if (inboundBufferStats == null) {
inboundBufferStats = value.getBufferStats();
} else {
PlayoutMetric audioJitterBuffer2 = inboundBufferStats.getAudioJitterBuffer();
if (!(audioJitterBuffer2 == null || (audioJitterBuffer = value.getBufferStats().getAudioJitterBuffer()) == null || audioJitterBuffer.getP75() <= audioJitterBuffer2.getP75())) {
inboundBufferStats = value.getBufferStats();
}
}
}
VoiceQualityKt.access$explodePlayoutMetric("audio_jitter_buffer", inboundBufferStats != null ? inboundBufferStats.getAudioJitterBuffer() : null, map);
VoiceQualityKt.access$explodePlayoutMetric("audio_jitter_target", inboundBufferStats != null ? inboundBufferStats.getAudioJitterTarget() : null, map);
VoiceQualityKt.access$explodePlayoutMetric("audio_jitter_delay", inboundBufferStats != null ? inboundBufferStats.getAudioJitterDelay() : null, map);
VoiceQualityKt.access$explodePlayoutMetric("relative_reception_delay", inboundBufferStats != null ? inboundBufferStats.getRelativeReceptionDelay() : null, map);
if (inboundBufferStats != null) {
playoutMetric = inboundBufferStats.getRelativePlayoutDelay();
}
VoiceQualityKt.access$explodePlayoutMetric("relative_playout_delay", playoutMetric, map);
}
public final void getDurationStats(Map<String, Object> map) {
m.checkNotNullParameter(map, "result");
map.put("duration_listening", Integer.valueOf(this._duration.getListening()));
map.put("duration_speaking", Integer.valueOf(this._duration.getSpeaking()));
map.put("duration_participation", Integer.valueOf(this._duration.getParticipation()));
map.put("duration_connected", Integer.valueOf(this._duration.getConnected()));
}
public final void getFrameOpStats(Map<String, Object> map) {
m.checkNotNullParameter(map, "result");
Long l = null;
Long l2 = null;
Long l3 = null;
Long l4 = null;
Long l5 = null;
Long l6 = null;
Long l7 = null;
for (Map.Entry<String, InboundAudio> entry : this._inboundStats.entrySet()) {
InboundAudio value = entry.getValue();
Long silent = value.getFrameOpStats().getSilent();
long j = 0;
if (silent != null) {
l = Long.valueOf((l != null ? l.longValue() : 0) + silent.longValue());
}
Long normal = value.getFrameOpStats().getNormal();
if (normal != null) {
l2 = Long.valueOf((l2 != null ? l2.longValue() : 0) + normal.longValue());
}
Long merged = value.getFrameOpStats().getMerged();
if (merged != null) {
l3 = Long.valueOf((l3 != null ? l3.longValue() : 0) + merged.longValue());
}
Long expanded = value.getFrameOpStats().getExpanded();
if (expanded != null) {
l4 = Long.valueOf((l4 != null ? l4.longValue() : 0) + expanded.longValue());
}
Long accelerated = value.getFrameOpStats().getAccelerated();
if (accelerated != null) {
l5 = Long.valueOf((l5 != null ? l5.longValue() : 0) + accelerated.longValue());
}
Long preemptiveExpanded = value.getFrameOpStats().getPreemptiveExpanded();
if (preemptiveExpanded != null) {
l6 = Long.valueOf((l6 != null ? l6.longValue() : 0) + preemptiveExpanded.longValue());
}
Long cng = value.getFrameOpStats().getCng();
if (cng != null) {
long longValue = cng.longValue();
if (l7 != null) {
j = l7.longValue();
}
l7 = Long.valueOf(j + longValue);
}
}
if (l != null) {
map.put("frame_op_silent", Long.valueOf(l.longValue()));
}
if (l2 != null) {
map.put("frame_op_normal", Long.valueOf(l2.longValue()));
}
if (l3 != null) {
map.put("frame_op_merged", Long.valueOf(l3.longValue()));
}
if (l4 != null) {
map.put("frame_op_expanded", Long.valueOf(l4.longValue()));
}
if (l5 != null) {
map.put("frame_op_accelerated", Long.valueOf(l5.longValue()));
}
if (l6 != null) {
map.put("frame_op_preemptive_expanded", Long.valueOf(l6.longValue()));
}
if (l7 != null) {
map.put("frame_op_cng", Long.valueOf(l7.longValue()));
}
}
/* JADX DEBUG: Multi-variable search result rejected for r1v2, resolved type: java.lang.Integer[] */
/* JADX DEBUG: Multi-variable search result rejected for r2v2, resolved type: java.lang.Object[] */
/* JADX DEBUG: Multi-variable search result rejected for r2v3, resolved type: java.lang.Object[] */
/* JADX DEBUG: Multi-variable search result rejected for r2v4, resolved type: java.lang.Object[] */
/* JADX DEBUG: Multi-variable search result rejected for r1v3, resolved type: java.lang.Object[] */
/* JADX DEBUG: Multi-variable search result rejected for r15v0, resolved type: java.lang.Integer */
/* JADX WARN: Multi-variable type inference failed */
public final void getMosStats(Map<String, Object> map) {
m.checkNotNullParameter(map, "result");
int i = 0;
Object[] objArr = {0, 0, 0, 0, 0};
double d = 0.0d;
int i2 = 0;
for (Map.Entry<String, InboundAudio> entry : this._inboundStats.entrySet()) {
InboundAudio value = entry.getValue();
d += value.getMosSum();
i2 += value.getMosCount();
for (int i3 = 0; i3 <= 4; i3++) {
objArr[i3] = Integer.valueOf(value.getMosBuckets()[i3].intValue() + objArr[i3].intValue());
}
}
if (i2 > 0) {
i = Double.valueOf(d / ((double) i2));
}
map.put("mos_mean", i);
map.put("mos_1", objArr[1]);
map.put("mos_2", objArr[2]);
map.put("mos_3", objArr[3]);
map.put("mos_4", objArr[4]);
}
public final void getPacketStats(Map<String, Object> map) {
m.checkNotNullParameter(map, "result");
long j = 0;
long j2 = 0;
for (Map.Entry<String, InboundAudio> entry : this._inboundStats.entrySet()) {
InboundAudio value = entry.getValue();
j += value.getPacketsReceived();
j2 += value.getPacketsLost();
}
map.put("packets_sent", Long.valueOf(this._outboundStats.getPacketsSent()));
map.put("packets_sent_lost", Integer.valueOf(this._outboundStats.getPacketsLost()));
map.put("packets_received", Long.valueOf(j));
map.put("packets_received_lost", Long.valueOf(j2));
}
public final void update(Stats stats) {
boolean z2;
int i;
boolean z3;
long j;
Iterator<Map.Entry<String, InboundRtpAudio>> it;
InboundAudio inboundAudio;
double d;
m.checkNotNullParameter(stats, "stats");
Duration duration = this._duration;
duration.setConnected(duration.getConnected() + 1);
long packetsSent = this._outboundStats.getPacketsSent();
long j2 = 0;
long j3 = 0;
for (Map.Entry<String, InboundAudio> entry : this._inboundStats.entrySet()) {
j3 += entry.getValue().getPacketsReceived();
}
OutboundRtpAudio outboundRtpAudio = stats.getOutboundRtpAudio();
this._outboundStats = outboundRtpAudio != null ? new OutboundAudio(outboundRtpAudio.getPacketsSent(), outboundRtpAudio.getPacketsLost()) : new OutboundAudio(0, 0);
Iterator<Map.Entry<String, InboundRtpAudio>> it2 = stats.getInboundRtpAudio().entrySet().iterator();
while (it2.hasNext()) {
Map.Entry<String, InboundRtpAudio> next = it2.next();
String key = next.getKey();
InboundRtpAudio value = next.getValue();
Transport transport = stats.getTransport();
int ping = transport != null ? transport.getPing() : 0;
long packetsReceived = value.getPacketsReceived();
long packetsLost = value.getPacketsLost();
int jitterBuffer = (int) value.getJitterBuffer();
InboundBufferStats inboundBufferStats = new InboundBufferStats(value.getAudioJitterBuffer(), value.getAudioJitterTarget(), value.getAudioJitterDelay(), value.getRelativeReceptionDelay(), value.getRelativePlayoutDelay());
InboundFrameOpStats inboundFrameOpStats = new InboundFrameOpStats(value.getOpSilence(), value.getOpNormal(), value.getOpMerge(), value.getOpExpand(), value.getOpAccelerate(), value.getOpPreemptiveExpand(), value.getOpCNG());
Map<String, InboundAudio> map = this._inboundStats;
InboundAudio inboundAudio2 = map.get(key);
if (inboundAudio2 != null) {
long packetsReceived2 = packetsReceived - inboundAudio2.getPacketsReceived();
long packetsLost2 = packetsLost - inboundAudio2.getPacketsLost();
Integer[] mosBuckets = inboundAudio2.getMosBuckets();
j = 0;
if (packetsReceived2 <= 0 || packetsLost2 < 0) {
it = it2;
d = 0.0d;
} else {
it = it2;
double access$_calculateMos = VoiceQualityKt.access$_calculateMos((double) (ping + jitterBuffer), VoiceQualityKt.access$clamp(((double) packetsLost2) / ((double) (packetsReceived2 + packetsLost2)), 0.0d, 1.0d));
int floor = (int) Math.floor(access$_calculateMos);
mosBuckets[floor] = Integer.valueOf(mosBuckets[floor].intValue() + 1);
d = access$_calculateMos;
}
inboundAudio = new InboundAudio(packetsReceived, packetsLost, d, inboundAudio2.getMosSum() + d, inboundAudio2.getMosCount() + (d > ((double) 0) ? 1 : 0), mosBuckets, inboundBufferStats, inboundFrameOpStats);
} else {
it = it2;
j = j2;
inboundAudio = new InboundAudio(packetsReceived, packetsLost, 0.0d, 0.0d, 0, new Integer[]{0, 0, 0, 0, 0}, inboundBufferStats, inboundFrameOpStats);
}
map.put(key, inboundAudio);
it2 = it;
j2 = j;
}
if (this._outboundStats.getPacketsSent() > packetsSent) {
Duration duration2 = this._duration;
duration2.setSpeaking(duration2.getSpeaking() + 1);
z2 = true;
} else {
z2 = false;
}
long j4 = j2;
for (Map.Entry<String, InboundAudio> entry2 : this._inboundStats.entrySet()) {
j4 += entry2.getValue().getPacketsReceived();
}
if (j4 > j3) {
Duration duration3 = this._duration;
i = 1;
duration3.setListening(duration3.getListening() + 1);
z3 = true;
} else {
i = 1;
z3 = false;
}
if (z2 || z3) {
Duration duration4 = this._duration;
duration4.setParticipation(duration4.getParticipation() + i);
}
}
}