package c.a.q.o0; import androidx.annotation.AnyThread; import com.discord.utilities.collections.Histogram; import com.discord.utilities.collections.ListenerCollection; import com.discord.utilities.collections.ListenerCollectionSubject; import com.discord.utilities.logging.Logger; import com.discord.utilities.system.DeviceResourceUsageMonitor; import com.discord.utilities.time.Clock; import com.discord.utilities.time.TimeSpan; import d0.t.h0; import d0.t.n; import d0.t.r; import d0.z.d.m; import d0.z.d.o; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import kotlin.Pair; import kotlin.Unit; import kotlin.jvm.functions.Function1; import kotlin.jvm.internal.DefaultConstructorMarker; /* compiled from: VideoQuality.kt */ public final class e { public static final List a = n.listOf((Object[]) new Integer[]{0, 500000, 1000000, 1500000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000}); public static final List b = n.listOf((Object[]) new Integer[]{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60}); /* renamed from: c reason: collision with root package name */ public static final List f231c = n.listOf((Object[]) new Integer[]{720, 480, 360}); public static final b d = new b(null); public final ListenerCollectionSubject e; public final ListenerCollection f; public final long g; public Long h; public final d i; public final d j; public final d k; public final g l = new g(); public final Map m = new LinkedHashMap(); public final Map n = new LinkedHashMap(); public final DeviceResourceUsageMonitor o; public final Logger p; public final Clock q; /* compiled from: VideoQuality.kt */ public static final class a { public long a; public long b; /* renamed from: c reason: collision with root package name */ public long f232c; public long d; public long e; public long f; public long g; public long h; public a() { this(0, 0, 0, 0, 0, 0, 0, 0, 255); } public a(long j, long j2, long j3, long j4, long j5, long j6, long j7, long j8) { this.a = j; this.b = j2; this.f232c = j3; this.d = j4; this.e = j5; this.f = j6; this.g = j7; this.h = j8; } /* JADX INFO: this call moved to the top of the method (can break code semantics) */ public /* synthetic */ a(long j, long j2, long j3, long j4, long j5, long j6, long j7, long j8, int i) { this((i & 1) != 0 ? 0 : j, (i & 2) != 0 ? 0 : j2, (i & 4) != 0 ? 0 : j3, (i & 8) != 0 ? 0 : j4, (i & 16) != 0 ? 0 : j5, (i & 32) != 0 ? 0 : j6, (i & 64) != 0 ? 0 : j7, (i & 128) == 0 ? j8 : 0); } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof a)) { return false; } a aVar = (a) obj; return this.a == aVar.a && this.b == aVar.b && this.f232c == aVar.f232c && this.d == aVar.d && this.e == aVar.e && this.f == aVar.f && this.g == aVar.g && this.h == aVar.h; } public int hashCode() { int a = a0.a.a.b.a(this.b); int a2 = a0.a.a.b.a(this.f232c); int a3 = a0.a.a.b.a(this.d); int a4 = a0.a.a.b.a(this.e); int a5 = a0.a.a.b.a(this.f); int a6 = a0.a.a.b.a(this.g); return a0.a.a.b.a(this.h) + ((a6 + ((a5 + ((a4 + ((a3 + ((a2 + ((a + (a0.a.a.b.a(this.a) * 31)) * 31)) * 31)) * 31)) * 31)) * 31)) * 31); } public String toString() { StringBuilder P = c.d.b.a.a.P("AggregatedProperties(framesCodec="); P.append(this.a); P.append(", framesNetwork="); P.append(this.b); P.append(", packets="); P.append(this.f232c); P.append(", packetsLost="); P.append(this.d); P.append(", framesDropped="); P.append(this.e); P.append(", bytes="); P.append(this.f); P.append(", nackCount="); P.append(this.g); P.append(", pliCount="); return c.d.b.a.a.A(P, this.h, ")"); } } /* compiled from: VideoQuality.kt */ public static final class b { public b(DefaultConstructorMarker defaultConstructorMarker) { } public static final long a(b bVar, Float f) { if (f != null) { return d0.a0.a.roundToLong(f.floatValue()); } return 0; } } /* compiled from: VideoQuality.kt */ public static abstract class c implements f { } /* compiled from: VideoQuality.kt */ public static final class d { public Long a; public long b; public d(boolean z2, long j) { this.a = z2 ? Long.valueOf(j) : null; } public final boolean a() { return this.a != null; } public final void b(boolean z2, long j) { Long l = this.a; if (l == null) { if (z2) { this.a = Long.valueOf(j); } } else if (l != null) { long longValue = l.longValue(); if (!z2) { this.b = (j - longValue) + this.b; this.a = null; } } } public final long c(long j) { Long l = this.a; if (l == null) { return this.b; } return (this.b + j) - l.longValue(); } } /* compiled from: VideoQuality.kt */ /* renamed from: c.a.q.o0.e$e reason: collision with other inner class name */ public static class C0043e { public List a = new ArrayList(); public final Histogram b = new Histogram(5, 0, 2, null); /* renamed from: c reason: collision with root package name */ public final Histogram f233c = new Histogram(25600, 0, 2, null); public Long d; public a e = new a(0, 0, 0, 0, 0, 0, 0, 0, 255); public long f; public Map g = new LinkedHashMap(); public Map h = new LinkedHashMap(); public float i; public Map j = new LinkedHashMap(); public C0043e() { for (Number number : e.a) { this.g.put(Integer.valueOf(number.intValue()), Float.valueOf(0.0f)); } for (Number number2 : e.b) { this.h.put(Integer.valueOf(number2.intValue()), Float.valueOf(0.0f)); } for (Number number3 : e.f231c) { this.j.put(Integer.valueOf(number3.intValue()), Float.valueOf(0.0f)); } } } /* compiled from: VideoQuality.kt */ public interface f { void onFirstFrameReceived(long j); void onFirstFrameSent(); } /* compiled from: VideoQuality.kt */ public static final class g extends C0043e { public int k = 2500000; public int l = 30; public long m; public long n; public long o; } /* compiled from: VideoQuality.kt */ public static final class h { public final long a; public final long b; /* renamed from: c reason: collision with root package name */ public final a f234c; public h() { this(0, 0, new a(0, 0, 0, 0, 0, 0, 0, 0, 255)); } public h(long j, long j2, a aVar) { m.checkNotNullParameter(aVar, "aggregatedProperties"); this.a = j; this.b = j2; this.f234c = aVar; } public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof h)) { return false; } h hVar = (h) obj; return this.a == hVar.a && this.b == hVar.b && m.areEqual(this.f234c, hVar.f234c); } public int hashCode() { int a = (a0.a.a.b.a(this.b) + (a0.a.a.b.a(this.a) * 31)) * 31; a aVar = this.f234c; return a + (aVar != null ? aVar.hashCode() : 0); } public String toString() { StringBuilder P = c.d.b.a.a.P("RawVideoStats(resolution="); P.append(this.a); P.append(", timestamp="); P.append(this.b); P.append(", aggregatedProperties="); P.append(this.f234c); P.append(")"); return P.toString(); } } /* compiled from: VideoQuality.kt */ public static final class i extends o implements Function1 { public final /* synthetic */ e this$0; /* JADX INFO: super call moved to the top of the method (can break code semantics) */ public i(e eVar) { super(1); this.this$0 = eVar; } /* Return type fixed from 'java.lang.Object' to match base method */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // kotlin.jvm.functions.Function1 public Unit invoke(DeviceResourceUsageMonitor.ResourceUsage resourceUsage) { DeviceResourceUsageMonitor.ResourceUsage resourceUsage2 = resourceUsage; m.checkNotNullParameter(resourceUsage2, "it"); e eVar = this.this$0; List list = e.a; synchronized (eVar) { for (Map.Entry entry : eVar.m.entrySet()) { C0043e value = entry.getValue(); value.b.addSample((long) resourceUsage2.getCpuUsagePercent()); value.f233c.addSample(resourceUsage2.getMemoryRssBytes()); } eVar.l.b.addSample((long) resourceUsage2.getCpuUsagePercent()); eVar.l.f233c.addSample(resourceUsage2.getMemoryRssBytes()); } return Unit.a; } } public e(Logger logger, Clock clock) { m.checkNotNullParameter(logger, "logger"); m.checkNotNullParameter(clock, "clock"); this.p = logger; this.q = clock; ListenerCollectionSubject listenerCollectionSubject = new ListenerCollectionSubject<>(); this.e = listenerCollectionSubject; this.f = listenerCollectionSubject; long currentTimeMillis = clock.currentTimeMillis(); this.g = currentTimeMillis; this.i = new d(false, currentTimeMillis); this.j = new d(false, currentTimeMillis); this.k = new d(false, currentTimeMillis); DeviceResourceUsageMonitor deviceResourceUsageMonitor = new DeviceResourceUsageMonitor(new TimeSpan(1, TimeUnit.SECONDS), clock, new i(this)); this.o = deviceResourceUsageMonitor; deviceResourceUsageMonitor.start(); } public final void a(C0043e eVar, h hVar) { eVar.a.add(hVar); if (eVar.a.size() >= 2) { List list = eVar.a; h hVar2 = list.get(list.size() - 1); List list2 = eVar.a; h hVar3 = list2.get(list2.size() - 2); f fVar = f.i; eVar.f = (hVar2.b - hVar3.b) + eVar.f; a aVar = eVar.e; a aVar2 = hVar2.f234c; a aVar3 = hVar3.f234c; aVar.a = fVar.a(aVar2.a, aVar3.a) + aVar.a; aVar.b = fVar.a(aVar2.b, aVar3.b) + aVar.b; aVar.f232c = fVar.a(aVar2.f232c, aVar3.f232c) + aVar.f232c; aVar.d = fVar.a(aVar2.d, aVar3.d) + aVar.d; aVar.e = fVar.a(aVar2.e, aVar3.e) + aVar.e; aVar.f = fVar.a(aVar2.f, aVar3.f) + aVar.f; aVar.g = fVar.a(aVar2.g, aVar3.g) + aVar.g; aVar.h = fVar.a(aVar2.h, aVar3.h) + aVar.h; a aVar4 = hVar2.f234c; long j = aVar4.f; long j2 = aVar4.a; long j3 = hVar2.b; long j4 = hVar2.a; float f2 = ((float) (j3 - hVar3.b)) / 1000.0f; eVar.i = (((float) j4) * f2) + eVar.i; if (eVar.a.size() >= 6) { List list3 = eVar.a; h hVar4 = list3.get(list3.size() - 3); a aVar5 = hVar4.f234c; long j5 = aVar5.f; long j6 = aVar5.a; long j7 = hVar4.b; Iterator it = f231c.iterator(); while (true) { float f3 = 0.0f; if (!it.hasNext()) { break; } int intValue = ((Number) it.next()).intValue(); if (j4 <= ((long) intValue)) { Map map = eVar.j; Integer valueOf = Integer.valueOf(intValue); Float f4 = eVar.j.get(Integer.valueOf(intValue)); if (f4 != null) { f3 = f4.floatValue(); } map.put(valueOf, Float.valueOf(f3 + f2)); } j2 = j2; j6 = j6; } float f5 = ((float) (j3 - j7)) / 1000.0f; float f6 = ((float) ((j - j5) * ((long) 8))) / f5; float f7 = ((float) (j2 - j6)) / f5; for (Number number : a) { int intValue2 = number.intValue(); if (f6 <= ((float) intValue2)) { Map map2 = eVar.g; Integer valueOf2 = Integer.valueOf(intValue2); Float f8 = eVar.g.get(Integer.valueOf(intValue2)); map2.put(valueOf2, Float.valueOf((f8 != null ? f8.floatValue() : 0.0f) + f2)); } } for (Number number2 : b) { int intValue3 = number2.intValue(); if (f7 <= ((float) intValue3)) { Map map3 = eVar.h; Integer valueOf3 = Integer.valueOf(intValue3); Float f9 = eVar.h.get(Integer.valueOf(intValue3)); map3.put(valueOf3, Float.valueOf((f9 != null ? f9.floatValue() : 0.0f) + f2)); } } r.removeFirst(eVar.a); } } } public final void b(int i2) { if (this.l.a.size() >= 2) { List list = this.l.a; long j = list.get(list.size() - 1).b; List list2 = this.l.a; float f2 = ((float) (j - list2.get(list2.size() - 2).b)) / 1000.0f; g gVar = this.l; long j2 = gVar.m; Float valueOf = Float.valueOf(((float) gVar.l) * f2); long j3 = 0; gVar.m = j2 + (valueOf != null ? d0.a0.a.roundToLong(valueOf.floatValue()) : 0); g gVar2 = this.l; long j4 = gVar2.n; Float valueOf2 = Float.valueOf((((float) i2) / 8.0f) * f2); gVar2.n = j4 + (valueOf2 != null ? d0.a0.a.roundToLong(valueOf2.floatValue()) : 0); g gVar3 = this.l; long j5 = gVar3.o; Float valueOf3 = Float.valueOf((((float) gVar3.k) / 8.0f) * f2); if (valueOf3 != null) { j3 = d0.a0.a.roundToLong(valueOf3.floatValue()); } gVar3.o = j5 + j3; } } @AnyThread public final synchronized Map c(String str) { C0043e eVar; m.checkNotNullParameter(str, "userId"); eVar = this.m.get(str); return eVar != null ? e(eVar) : null; } @AnyThread public final synchronized Map d() { g gVar; float f2; int i2; Float valueOf; Float valueOf2; Float valueOf3; gVar = this.l; f2 = ((float) gVar.f) / 1000.0f; i2 = (f2 > ((float) 0) ? 1 : (f2 == ((float) 0) ? 0 : -1)); return h0.plus(e(this.l), h0.mapOf(d0.o.to("target_bitrate_max", Long.valueOf((i2 <= 0 || (valueOf3 = Float.valueOf(((float) (gVar.o * ((long) 8))) / f2)) == null) ? 0 : d0.a0.a.roundToLong(valueOf3.floatValue()))), d0.o.to("target_bitrate_network", Long.valueOf((i2 <= 0 || (valueOf2 = Float.valueOf(((float) (this.l.n * ((long) 8))) / f2)) == null) ? 0 : d0.a0.a.roundToLong(valueOf2.floatValue()))), d0.o.to("target_fps", Long.valueOf((i2 <= 0 || (valueOf = Float.valueOf(((float) this.l.m) / f2)) == null) ? 0 : d0.a0.a.roundToLong(valueOf.floatValue()))), d0.o.to("duration_encoder_nvidia_cuda", 0L), d0.o.to("duration_encoder_nvidia_direct3d", 0L), d0.o.to("duration_encoder_openh264", 0L), d0.o.to("duration_encoder_videotoolbox", 0L), d0.o.to("duration_encoder_amd_direct3d", 0L), d0.o.to("duration_encoder_intel", 0L), d0.o.to("duration_encoder_intel_direct3d", 0L), d0.o.to("duration_encoder_unknown", 0L))); } /* JADX DEBUG: Can't convert new array creation: APUT found in different block: 0x04e0: APUT (r6v4 kotlin.Pair[]) (6 ??[int, float, short, byte, char]) (wrap: kotlin.Pair : 0x04db: INVOKE (r1v3 kotlin.Pair) = ("time_to_first_frame_ms") (wrap: java.lang.Long : 0x04d4: INVOKE (r1v2 java.lang.Long) = (r4v22 long) type: STATIC call: java.lang.Long.valueOf(long):java.lang.Long) type: STATIC call: d0.o.to(java.lang.Object, java.lang.Object):kotlin.Pair) */ public final Map e(C0043e eVar) { Float valueOf; long currentTimeMillis = this.q.currentTimeMillis(); Long l = this.h; float longValue = ((float) (l != null ? l.longValue() - this.g : currentTimeMillis - this.g)) / 1000.0f; float f2 = ((float) eVar.f) / 1000.0f; int i2 = (f2 > ((float) 0) ? 1 : (f2 == ((float) 0) ? 0 : -1)); long roundToLong = (i2 <= 0 || (valueOf = Float.valueOf(eVar.i / f2)) == null) ? 0 : d0.a0.a.roundToLong(valueOf.floatValue()); Histogram.Report report = eVar.b.getReport(); Histogram.Report report2 = eVar.f233c.getReport(); b bVar = d; long j = (long) 1024; Map mapOf = h0.mapOf(d0.o.to("duration", Double.valueOf(Math.floor((double) longValue))), c.d.b.a.a.Y(bVar, eVar.g.get(8000000), "duration_stream_under_8mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(7000000), "duration_stream_under_7mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(6000000), "duration_stream_under_6mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(5000000), "duration_stream_under_5mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(4000000), "duration_stream_under_4mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(3000000), "duration_stream_under_3mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(2000000), "duration_stream_under_2mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(1500000), "duration_stream_under_1_5mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(1000000), "duration_stream_under_1mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(500000), "duration_stream_under_0_5mbps"), c.d.b.a.a.Y(bVar, eVar.g.get(0), "duration_stream_at_0mbps"), c.d.b.a.a.Y(bVar, eVar.h.get(60), "duration_fps_under_60"), c.d.b.a.a.Y(bVar, eVar.h.get(55), "duration_fps_under_55"), c.d.b.a.a.Y(bVar, eVar.h.get(50), "duration_fps_under_50"), c.d.b.a.a.Y(bVar, eVar.h.get(45), "duration_fps_under_45"), c.d.b.a.a.Y(bVar, eVar.h.get(40), "duration_fps_under_40"), c.d.b.a.a.Y(bVar, eVar.h.get(35), "duration_fps_under_35"), c.d.b.a.a.Y(bVar, eVar.h.get(30), "duration_fps_under_30"), c.d.b.a.a.Y(bVar, eVar.h.get(25), "duration_fps_under_25"), c.d.b.a.a.Y(bVar, eVar.h.get(20), "duration_fps_under_20"), c.d.b.a.a.Y(bVar, eVar.h.get(15), "duration_fps_under_15"), c.d.b.a.a.Y(bVar, eVar.h.get(10), "duration_fps_under_10"), c.d.b.a.a.Y(bVar, eVar.h.get(5), "duration_fps_under_5"), c.d.b.a.a.Y(bVar, eVar.h.get(0), "duration_fps_at_0"), d0.o.to("avg_resolution", Long.valueOf(roundToLong)), c.d.b.a.a.Y(bVar, eVar.j.get(720), "duration_resolution_under_720"), c.d.b.a.a.Y(bVar, eVar.j.get(480), "duration_resolution_under_480"), c.d.b.a.a.Y(bVar, eVar.j.get(360), "duration_resolution_under_360"), d0.o.to("num_pauses", 0), d0.o.to("duration_paused", Long.valueOf(b.a(bVar, Float.valueOf(((float) this.i.c(currentTimeMillis)) / 1000.0f)))), d0.o.to("duration_zero_receivers", Long.valueOf(b.a(bVar, Float.valueOf(((float) this.j.c(currentTimeMillis)) / 1000.0f)))), d0.o.to("duration_video_stopped", Long.valueOf(b.a(bVar, Float.valueOf(((float) this.k.c(currentTimeMillis)) / 1000.0f)))), d0.o.to("client_performance_cpu_percentile25", Long.valueOf(report.getPercentile25())), d0.o.to("client_performance_cpu_percentile50", Long.valueOf(report.getPercentile50())), d0.o.to("client_performance_cpu_percentile75", Long.valueOf(report.getPercentile75())), d0.o.to("client_performance_cpu_percentile90", Long.valueOf(report.getPercentile90())), d0.o.to("client_performance_cpu_percentile95", Long.valueOf(report.getPercentile95())), d0.o.to("client_performance_memory_percentile25", Long.valueOf(report2.getPercentile25() / j)), d0.o.to("client_performance_memory_percentile50", Long.valueOf(report2.getPercentile50() / j)), d0.o.to("client_performance_memory_percentile75", Long.valueOf(report2.getPercentile75() / j)), d0.o.to("client_performance_memory_percentile90", Long.valueOf(report2.getPercentile90() / j)), d0.o.to("client_performance_memory_percentile95", Long.valueOf(report2.getPercentile95() / j)), d0.o.to("client_performance_memory_min", Long.valueOf(report2.getMin() / j)), d0.o.to("client_performance_memory_max", Long.valueOf(report2.getMax() / j))); a aVar = eVar.e; long a2 = i2 > 0 ? b.a(bVar, Float.valueOf(((float) (aVar.f * ((long) 8))) / f2)) : 0; long a3 = i2 > 0 ? b.a(bVar, Float.valueOf(((float) aVar.a) / f2)) : 0; Pair[] pairArr = new Pair[10]; pairArr[0] = d0.o.to("avg_bitrate", Long.valueOf(a2)); pairArr[1] = d0.o.to("avg_fps", Long.valueOf(a3)); pairArr[2] = d0.o.to("num_bytes", Long.valueOf(aVar.f)); pairArr[3] = d0.o.to("num_packets_lost", Long.valueOf(aVar.d)); pairArr[4] = d0.o.to("num_packets", Long.valueOf(aVar.f232c)); pairArr[5] = d0.o.to("num_frames", Long.valueOf(aVar.b)); Long l2 = eVar.d; pairArr[6] = d0.o.to("time_to_first_frame_ms", Long.valueOf(l2 != null ? l2.longValue() : 0)); pairArr[7] = d0.o.to("num_frames_dropped", Long.valueOf(aVar.e)); pairArr[8] = d0.o.to("num_nacks", Long.valueOf(aVar.g)); pairArr[9] = d0.o.to("num_plis", Long.valueOf(aVar.h)); return h0.plus(mapOf, h0.mapOf(pairArr)); } public final void f(Boolean bool, Integer num, long j) { boolean z2 = false; if (num != null) { this.j.b(num.intValue() == 0, j); } if (this.i.a() || this.j.a()) { z2 = true; } if (z2 != this.k.a()) { this.k.b(z2, j); this.l.a.clear(); } } }