discord-jadx/app/src/main/java/com/discord/rtcconnection/RtcConnection.java

954 lines
31 KiB
Java

package com.discord.rtcconnection;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.AnyThread;
import androidx.core.app.NotificationCompat;
import c.a.r.a0;
import c.a.r.b0;
import c.a.r.f0;
import c.a.r.g0;
import c.a.r.h0;
import c.a.r.i0;
import c.a.r.j;
import c.a.r.p;
import c.a.r.p0.e;
import c.a.r.q;
import c.a.r.r;
import c.a.r.z;
import co.discord.media_engine.InboundRtpAudio;
import co.discord.media_engine.OutboundRtpAudio;
import co.discord.media_engine.Stats;
import co.discord.media_engine.VoiceQuality;
import com.discord.models.domain.ModelAuditLogEntry;
import com.discord.rtcconnection.MediaSinkWantsManager;
import com.discord.rtcconnection.mediaengine.MediaEngine;
import com.discord.rtcconnection.mediaengine.MediaEngineConnection;
import com.discord.rtcconnection.mediaengine.ThumbnailEmitter;
import com.discord.utilities.debug.DebugPrintBuilder;
import com.discord.utilities.debug.DebugPrintable;
import com.discord.utilities.logging.Logger;
import com.discord.utilities.networking.Backoff;
import com.discord.utilities.networking.NetworkMonitor;
import com.discord.utilities.time.Clock;
import d0.g;
import d0.g0.s;
import d0.t.u;
import d0.z.d.m;
import d0.z.d.o;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import kotlin.Lazy;
import kotlin.NoWhenBranchMatchedException;
import kotlin.Unit;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.DefaultConstructorMarker;
import rx.Observable;
import rx.Subscription;
import rx.subjects.BehaviorSubject;
/* compiled from: RtcConnection.kt */
public final class RtcConnection implements DebugPrintable, MediaSinkWantsManager.a, e.f {
public static int i;
public static final a j = new a(null);
public final Lazy A;
public Long B;
public Long C;
public int D;
public Subscription E;
public final MediaSinkWantsManager F;
public final Subscription G;
public boolean H;
public String I;
public long J;
public final h0 K;
public final b0 L;
public final Long M;
public final long N;
public String O;
public final boolean P;
public final String Q;
public final long R;
public final MediaEngine S;
public final Logger T;
public final Clock U;
public final d V;
public final Map<Long, Boolean> W;
public final Map<Long, Float> X;
public final String Y;
public final boolean Z;
/* renamed from: a0 reason: collision with root package name */
public final String f2117a0;
/* renamed from: b0 reason: collision with root package name */
public final String f2118b0;
public final String k;
public final String l;
public final List<c> m;
public c.a.r.p0.d n;
public boolean o;
public final Backoff p;
public MediaEngineConnection.TransportInfo q;
public StateChange r;
/* renamed from: s reason: collision with root package name */
public BehaviorSubject<StateChange> f2119s;
public boolean t;
public List<Long> u;
public c.a.r.o0.a v;
public MediaEngineConnection w;
/* renamed from: x reason: collision with root package name */
public String f2120x;
/* renamed from: y reason: collision with root package name */
public Integer f2121y;
/* renamed from: z reason: collision with root package name */
public int f2122z;
/* compiled from: RtcConnection.kt */
public enum AnalyticsEvent {
VOICE_CONNECTION_SUCCESS,
VOICE_CONNECTION_FAILURE,
VOICE_DISCONNECT,
VIDEO_STREAM_ENDED,
MEDIA_SESSION_JOINED
}
/* compiled from: RtcConnection.kt */
public static final class Metadata {
public final String a;
public final String b;
/* renamed from: c reason: collision with root package name */
public final Long f2123c;
public final Long d;
public final String e;
public Metadata(String str, String str2, Long l, Long l2, String str3) {
m.checkNotNullParameter(str, "rtcConnectionId");
this.a = str;
this.b = str2;
this.f2123c = l;
this.d = l2;
this.e = str3;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Metadata)) {
return false;
}
Metadata metadata = (Metadata) obj;
return m.areEqual(this.a, metadata.a) && m.areEqual(this.b, metadata.b) && m.areEqual(this.f2123c, metadata.f2123c) && m.areEqual(this.d, metadata.d) && m.areEqual(this.e, metadata.e);
}
public int hashCode() {
String str = this.a;
int i = 0;
int hashCode = (str != null ? str.hashCode() : 0) * 31;
String str2 = this.b;
int hashCode2 = (hashCode + (str2 != null ? str2.hashCode() : 0)) * 31;
Long l = this.f2123c;
int hashCode3 = (hashCode2 + (l != null ? l.hashCode() : 0)) * 31;
Long l2 = this.d;
int hashCode4 = (hashCode3 + (l2 != null ? l2.hashCode() : 0)) * 31;
String str3 = this.e;
if (str3 != null) {
i = str3.hashCode();
}
return hashCode4 + i;
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("Metadata(rtcConnectionId=");
K.append(this.a);
K.append(", mediaSessionId=");
K.append(this.b);
K.append(", channelId=");
K.append(this.f2123c);
K.append(", guildId=");
K.append(this.d);
K.append(", streamKey=");
return c.d.b.a.a.C(K, this.e, ")");
}
}
/* compiled from: RtcConnection.kt */
public enum Quality {
UNKNOWN,
BAD,
AVERAGE,
FINE;
public static final a Companion = new a(null);
/* compiled from: RtcConnection.kt */
public static final class a {
public a(DefaultConstructorMarker defaultConstructorMarker) {
}
}
}
/* compiled from: RtcConnection.kt */
public static abstract class State {
/* compiled from: RtcConnection.kt */
public static final class a extends State {
public static final a a = new a();
public a() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class b extends State {
public static final b a = new b();
public b() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class c extends State {
public static final c a = new c();
public c() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class d extends State {
public final boolean a;
public d(boolean z2) {
super(null);
this.a = z2;
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof d) && this.a == ((d) obj).a;
}
return true;
}
public int hashCode() {
boolean z2 = this.a;
if (z2) {
return 1;
}
return z2 ? 1 : 0;
}
@Override // com.discord.rtcconnection.RtcConnection.State
public String toString() {
return c.d.b.a.a.F(c.d.b.a.a.K("Disconnected(willReconnect="), this.a, ")");
}
}
/* compiled from: RtcConnection.kt */
public static final class e extends State {
public static final e a = new e();
public e() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class f extends State {
public static final f a = new f();
public f() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class g extends State {
public static final g a = new g();
public g() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class h extends State {
public static final h a = new h();
public h() {
super(null);
}
}
public State() {
}
public State(DefaultConstructorMarker defaultConstructorMarker) {
}
public String toString() {
if (this instanceof d) {
return super.toString();
}
String simpleName = getClass().getSimpleName();
m.checkNotNullExpressionValue(simpleName, "javaClass.simpleName");
return simpleName;
}
}
/* compiled from: RtcConnection.kt */
public static final class StateChange {
public final State a;
public final Metadata b;
public StateChange(State state, Metadata metadata) {
m.checkNotNullParameter(state, "state");
this.a = state;
this.b = metadata;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof StateChange)) {
return false;
}
StateChange stateChange = (StateChange) obj;
return m.areEqual(this.a, stateChange.a) && m.areEqual(this.b, stateChange.b);
}
public int hashCode() {
State state = this.a;
int i = 0;
int hashCode = (state != null ? state.hashCode() : 0) * 31;
Metadata metadata = this.b;
if (metadata != null) {
i = metadata.hashCode();
}
return hashCode + i;
}
public String toString() {
StringBuilder K = c.d.b.a.a.K("StateChange(state=");
K.append(this.a);
K.append(", metadata=");
K.append(this.b);
K.append(")");
return K.toString();
}
}
/* compiled from: RtcConnection.kt */
public static final class a {
public a(DefaultConstructorMarker defaultConstructorMarker) {
}
}
/* compiled from: RtcConnection.kt */
public static abstract class b implements c {
@Override // com.discord.rtcconnection.RtcConnection.c
public void onAnalyticsEvent(AnalyticsEvent analyticsEvent, Map<String, Object> map) {
m.checkNotNullParameter(analyticsEvent, NotificationCompat.CATEGORY_EVENT);
m.checkNotNullParameter(map, "properties");
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onFatalClose() {
}
@Override // c.a.r.p0.e.f
public void onFirstFrameReceived(long j) {
}
@Override // c.a.r.p0.e.f
public void onFirstFrameSent() {
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onMediaEngineConnectionConnected(RtcConnection rtcConnection) {
m.checkNotNullParameter(rtcConnection, "connection");
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onMediaSessionIdReceived() {
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onQualityUpdate(Quality quality) {
m.checkNotNullParameter(quality, "quality");
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onSpeaking(long j, boolean z2) {
}
@Override // com.discord.rtcconnection.RtcConnection.c
public abstract void onStateChange(StateChange stateChange);
@Override // com.discord.rtcconnection.RtcConnection.c
public void onUserCreated(RtcConnection rtcConnection, long j) {
m.checkNotNullParameter(rtcConnection, "connection");
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onVideoMetadata(VideoMetadata videoMetadata) {
m.checkNotNullParameter(videoMetadata, "metadata");
}
@Override // com.discord.rtcconnection.RtcConnection.c
public void onVideoStream(long j, Integer num, int i, int i2, int i3) {
}
}
/* compiled from: RtcConnection.kt */
public interface c extends e.f {
void onAnalyticsEvent(AnalyticsEvent analyticsEvent, Map<String, Object> map);
void onFatalClose();
void onMediaEngineConnectionConnected(RtcConnection rtcConnection);
void onMediaSessionIdReceived();
void onQualityUpdate(Quality quality);
void onSpeaking(long j, boolean z2);
void onStateChange(StateChange stateChange);
void onUserCreated(RtcConnection rtcConnection, long j);
void onVideoMetadata(VideoMetadata videoMetadata);
void onVideoStream(long j, Integer num, int i, int i2, int i3);
}
/* compiled from: RtcConnection.kt */
public static abstract class d {
/* compiled from: RtcConnection.kt */
public static final class a extends d {
public static final a a = new a();
public a() {
super(null);
}
}
/* compiled from: RtcConnection.kt */
public static final class b extends d {
public final long a;
public b(long j) {
super(null);
this.a = j;
}
public boolean equals(Object obj) {
if (this != obj) {
return (obj instanceof b) && this.a == ((b) obj).a;
}
return true;
}
public int hashCode() {
return a0.a.a.b.a(this.a);
}
public String toString() {
return c.d.b.a.a.y(c.d.b.a.a.K("Stream(senderId="), this.a, ")");
}
}
public d(DefaultConstructorMarker defaultConstructorMarker) {
}
}
/* compiled from: RtcConnection.kt */
public static final class e extends o implements Function0<Unit> {
public final /* synthetic */ RtcConnection this$0;
/* JADX INFO: super call moved to the top of the method (can break code semantics) */
public e(RtcConnection rtcConnection) {
super(0);
this.this$0 = rtcConnection;
}
/* Return type fixed from 'java.lang.Object' to match base method */
@Override // kotlin.jvm.functions.Function0
/* renamed from: invoke */
public Unit mo1invoke() {
this.this$0.f("Force Close");
return Unit.a;
}
}
public RtcConnection(Long l, long j2, String str, boolean z2, String str2, long j3, MediaEngine mediaEngine, Logger logger, Clock clock, d dVar, NetworkMonitor networkMonitor, Map map, Map map2, String str3, boolean z3, String str4, String str5, int i2) {
Subscription subscription;
MediaSinkWantsManager mediaSinkWantsManager;
d dVar2 = (i2 & 512) != 0 ? d.a.a : dVar;
Map linkedHashMap = (i2 & 2048) != 0 ? new LinkedHashMap() : map;
LinkedHashMap linkedHashMap2 = (i2 & 4096) != 0 ? new LinkedHashMap() : null;
String str6 = (i2 & 8192) != 0 ? null : str3;
boolean z4 = (i2 & 16384) != 0 ? false : z3;
String str7 = (i2 & 65536) != 0 ? null : str5;
m.checkNotNullParameter(str, "sessionId");
m.checkNotNullParameter(str2, "rtcServerId");
m.checkNotNullParameter(mediaEngine, "mediaEngine");
m.checkNotNullParameter(logger, "logger");
m.checkNotNullParameter(clock, "clock");
m.checkNotNullParameter(dVar2, "rtcConnectionType");
m.checkNotNullParameter(networkMonitor, "networkMonitor");
m.checkNotNullParameter(linkedHashMap, "mutedUsers");
m.checkNotNullParameter(linkedHashMap2, "userVolumes");
m.checkNotNullParameter(str4, "loggingTagPrefix");
this.M = l;
this.N = j2;
this.O = str;
this.P = z2;
this.Q = str2;
this.R = j3;
this.S = mediaEngine;
this.T = logger;
this.U = clock;
this.V = dVar2;
this.W = linkedHashMap;
this.X = linkedHashMap2;
this.Y = str6;
this.Z = z4;
this.f2117a0 = str4;
this.f2118b0 = str7;
StringBuilder O = c.d.b.a.a.O(str4, "->RtcConnection ");
int i3 = i + 1;
i = i3;
O.append(i3);
this.k = O.toString();
String uuid = UUID.randomUUID().toString();
m.checkNotNullExpressionValue(uuid, "UUID.randomUUID().toString()");
this.l = uuid;
ArrayList arrayList = new ArrayList();
this.m = arrayList;
this.p = new Backoff(1000, 10000, 0, false, null, 28, null);
StateChange stateChange = new StateChange(new State.d(false), null);
this.r = stateChange;
this.f2119s = BehaviorSubject.l0(stateChange);
this.u = new ArrayList();
this.A = g.lazy(new i0(this));
if (z4) {
subscription = null;
mediaSinkWantsManager = new MediaSinkWantsManager(j3, mediaEngine.c(), new c.a.r.e(null, 1), logger, this);
} else {
mediaSinkWantsManager = null;
subscription = null;
}
this.F = mediaSinkWantsManager;
if (z4) {
m.checkNotNull(mediaSinkWantsManager);
Observable<Map<String, EncodeQuality>> r = mediaSinkWantsManager.f.r();
m.checkNotNullExpressionValue(r, "mediaSinkWantsSubject.distinctUntilChanged()");
subscription = Observable.j(r, this.f2119s, z.i).V(new g0(new a0(this)));
}
this.G = subscription;
s("Created RtcConnection. GuildID: " + l + " ChannelID: " + j2);
networkMonitor.observeIsConnected().S(1).W(new p(this), new q(this));
arrayList.add(new r(this));
this.K = new h0(this);
this.L = new b0(this);
}
public static void k(RtcConnection rtcConnection, boolean z2, String str, Throwable th, boolean z3, int i2) {
if ((i2 & 4) != 0) {
th = null;
}
if ((i2 & 8) != 0) {
z3 = true;
}
if (z3) {
p(rtcConnection, str, th, null, 4);
} else {
rtcConnection.T.i(rtcConnection.k, str, th);
}
c.a.r.p0.d dVar = rtcConnection.n;
if (dVar != null) {
dVar.a();
}
rtcConnection.n = null;
MediaEngineConnection mediaEngineConnection = rtcConnection.w;
if (mediaEngineConnection != null) {
mediaEngineConnection.destroy();
}
rtcConnection.w = null;
rtcConnection.o = false;
rtcConnection.p.cancel();
rtcConnection.v(new State.d(z2));
if (z2) {
rtcConnection.r();
return;
}
for (c cVar : rtcConnection.m) {
cVar.onFatalClose();
}
rtcConnection.f(str);
}
public static void p(RtcConnection rtcConnection, String str, Throwable th, Map map, int i2) {
if ((i2 & 2) != 0) {
th = null;
}
int i3 = i2 & 4;
rtcConnection.T.e(rtcConnection.k, str, th, null);
}
@Override // com.discord.rtcconnection.MediaSinkWantsManager.a
public void a(long j2, long j3, long j4, VideoMetadata videoMetadata) {
d(j2, j3, j4, videoMetadata);
}
public final Map<String, Object> b(Map<String, Object> map) {
String str = this.f2120x;
if (str != null) {
map.put("hostname", str);
}
Integer num = this.f2121y;
if (num != null) {
map.put("port", Integer.valueOf(num.intValue()));
}
return map;
}
public final void c(c cVar) {
m.checkNotNullParameter(cVar, "listener");
this.m.add(cVar);
}
public final void d(long j2, long j3, long j4, VideoMetadata videoMetadata) {
MediaEngineConnection mediaEngineConnection = this.w;
if (mediaEngineConnection != null) {
mediaEngineConnection.s(j2, (int) j3, Integer.valueOf((int) j4), g(j2), h(j2));
}
for (c cVar : this.m) {
cVar.onUserCreated(this, j2);
}
if (videoMetadata != null) {
for (c cVar2 : this.m) {
cVar2.onVideoMetadata(videoMetadata);
}
}
}
@Override // com.discord.utilities.debug.DebugPrintable
public void debugPrint(DebugPrintBuilder debugPrintBuilder) {
m.checkNotNullParameter(debugPrintBuilder, "dp");
debugPrintBuilder.appendKeyValue(ModelAuditLogEntry.CHANGE_KEY_ID, this.l);
debugPrintBuilder.appendKeyValue("mediaSessionId", this.I);
debugPrintBuilder.appendKeyValue("parentMediaSessionId", this.Y);
debugPrintBuilder.appendKeyValue("hostname", this.f2120x);
debugPrintBuilder.appendKeyValue("channelId", Long.valueOf(this.N));
debugPrintBuilder.appendKeyValue("guildId", this.M);
debugPrintBuilder.appendKeyValue("streamKey", this.f2118b0);
debugPrintBuilder.appendKeyValue("isVideoEnabled", Boolean.valueOf(this.P));
debugPrintBuilder.appendKeyValue("rtcServerId", this.Q);
debugPrintBuilder.appendKeyValue("userId", Long.valueOf(this.R));
debugPrintBuilder.appendKeyValue("rtcConnectionType", this.V);
debugPrintBuilder.appendKeyValue("enableMediaSinkWants", Boolean.valueOf(this.Z));
debugPrintBuilder.appendKeyValue("socket", (DebugPrintable) this.v);
debugPrintBuilder.appendKeyValue("sentVideo", Boolean.valueOf(this.o));
}
public final void e() {
t(new e(this));
}
public final void f(String str) {
this.p.cancel();
c.a.r.o0.a aVar = this.v;
if (aVar != null) {
aVar.p.clear();
aVar.e();
}
this.v = null;
if (!(this.r.a instanceof State.d)) {
o(false, str);
d dVar = this.V;
if (dVar instanceof d.b) {
Map<String, Object> b2 = j().b(String.valueOf(((d.b) dVar).a));
if (b2 != null) {
m(((d.b) this.V).a, b2);
}
if (this.o) {
n(this.R, j().c());
}
}
}
MediaSinkWantsManager mediaSinkWantsManager = this.F;
if (mediaSinkWantsManager != null) {
mediaSinkWantsManager.b(new c.a.r.g(mediaSinkWantsManager));
}
Subscription subscription = this.G;
if (subscription != null) {
subscription.unsubscribe();
}
Subscription subscription2 = this.E;
if (subscription2 != null) {
subscription2.unsubscribe();
}
this.E = null;
MediaEngineConnection mediaEngineConnection = this.w;
if (mediaEngineConnection != null) {
mediaEngineConnection.destroy();
}
this.w = null;
v(new State.d(false));
s("Destroy internal RTC connection: " + str);
this.m.clear();
this.o = false;
this.t = true;
}
public final boolean g(long j2) {
Boolean bool = this.W.get(Long.valueOf(j2));
if (bool != null) {
return bool.booleanValue();
}
return false;
}
public final float h(long j2) {
Float f = this.X.get(Long.valueOf(j2));
if (f != null) {
return f.floatValue();
}
return 1.0f;
}
public final Metadata i() {
return new Metadata(this.l, this.I, Long.valueOf(this.N), this.M, this.f2118b0);
}
public final c.a.r.p0.e j() {
return (c.a.r.p0.e) this.A.getValue();
}
public final void l(long j2, Map<String, ? extends Object> map) {
HashMap hashMap = new HashMap();
Long l = this.M;
if (l != null) {
l.longValue();
hashMap.put(ModelAuditLogEntry.CHANGE_KEY_GUILD_ID, this.M);
}
hashMap.put(ModelAuditLogEntry.CHANGE_KEY_CHANNEL_ID, Long.valueOf(this.N));
hashMap.put("sender_user_id", Long.valueOf(j2));
hashMap.putAll(map);
q(AnalyticsEvent.VIDEO_STREAM_ENDED, hashMap);
}
public final void m(long j2, Map<String, ? extends Object> map) {
if (map != null) {
l(j2, d0.t.h0.plus(map, d0.t.g0.mapOf(d0.o.to("participant_type", "receiver"))));
}
}
public final void n(long j2, Map<String, ? extends Object> map) {
if (map != null) {
l(j2, d0.t.h0.plus(map, d0.t.g0.mapOf(d0.o.to("participant_type", this.V instanceof d.b ? "streamer" : NotificationCompat.MessagingStyle.Message.KEY_SENDER))));
}
}
public final void o(boolean z2, String str) {
String str2;
Stats stats;
VoiceQuality voiceQuality;
Map<String, Object> mutableMapOf = d0.t.h0.mutableMapOf(d0.o.to("ping_bad_count", Integer.valueOf(this.f2122z)), d0.o.to("connect_count", Integer.valueOf(this.D)), d0.o.to("channel_count", 1));
b(mutableMapOf);
mutableMapOf.put("reconnect", Boolean.valueOf(z2));
if (str != null) {
mutableMapOf.put(ModelAuditLogEntry.CHANGE_KEY_REASON, str);
}
double averageOfLong = u.averageOfLong(this.u);
if (!Double.isNaN(averageOfLong)) {
mutableMapOf.put("ping_average", Integer.valueOf(d0.a0.a.roundToInt(averageOfLong)));
}
String str3 = this.I;
if (str3 != null) {
mutableMapOf.put("media_session_id", str3);
}
c.a.r.p0.d dVar = this.n;
if (!(dVar == null || (stats = (Stats) u.lastOrNull(dVar.a)) == null)) {
OutboundRtpAudio outboundRtpAudio = stats.getOutboundRtpAudio();
if (outboundRtpAudio != null) {
mutableMapOf.put("packets_sent", Long.valueOf(outboundRtpAudio.getPacketsSent()));
mutableMapOf.put("packets_sent_lost", Integer.valueOf(outboundRtpAudio.getPacketsLost()));
}
long j2 = 0;
long j3 = 0;
for (InboundRtpAudio inboundRtpAudio : stats.getInboundRtpAudio().values()) {
j3 += inboundRtpAudio.getPacketsLost();
j2 += inboundRtpAudio.getPacketsReceived();
}
mutableMapOf.put("packets_received", Long.valueOf(j2));
mutableMapOf.put("packets_received_lost", Long.valueOf(j3));
c.a.r.p0.d dVar2 = this.n;
if (!(dVar2 == null || (voiceQuality = dVar2.f) == null)) {
voiceQuality.getDurationStats(mutableMapOf);
voiceQuality.getMosStats(mutableMapOf);
voiceQuality.getPacketStats(mutableMapOf);
voiceQuality.getBufferStats(mutableMapOf);
voiceQuality.getFrameOpStats(mutableMapOf);
}
}
Long l = this.C;
MediaEngineConnection.TransportInfo.Protocol protocol = null;
Long valueOf = l != null ? Long.valueOf(this.U.currentTimeMillis() - l.longValue()) : null;
if (valueOf != null) {
mutableMapOf.put("duration", Long.valueOf(valueOf.longValue()));
}
MediaEngineConnection.TransportInfo transportInfo = this.q;
if (transportInfo != null) {
protocol = transportInfo.f2135c;
}
if (protocol != null) {
int ordinal = protocol.ordinal();
if (ordinal == 0) {
str2 = "udp";
} else if (ordinal == 1) {
str2 = "tcp";
} else {
throw new NoWhenBranchMatchedException();
}
mutableMapOf.put("protocol", str2);
}
q(AnalyticsEvent.VOICE_DISCONNECT, mutableMapOf);
if (this.V instanceof d.a) {
for (String str4 : u.toList(j().l.keySet())) {
Long longOrNull = s.toLongOrNull(str4);
if (longOrNull != null) {
m(longOrNull.longValue(), j().b(str4));
}
}
if (this.o) {
n(this.R, j().c());
}
}
}
@Override // c.a.r.p0.e.f
public void onFirstFrameReceived(long j2) {
for (c cVar : this.m) {
cVar.onFirstFrameReceived(j2);
}
}
@Override // c.a.r.p0.e.f
public void onFirstFrameSent() {
for (c cVar : this.m) {
cVar.onFirstFrameSent();
}
}
public final void q(AnalyticsEvent analyticsEvent, Map<String, Object> map) {
String str;
map.put("rtc_connection_id", this.l);
d dVar = this.V;
if (m.areEqual(dVar, d.a.a)) {
str = "default";
} else if (dVar instanceof d.b) {
str = "stream";
} else {
throw new NoWhenBranchMatchedException();
}
map.put("context", str);
String str2 = this.I;
if (str2 != null) {
map.put("media_session_id", str2);
}
String str3 = this.Y;
if (str3 != null) {
map.put("parent_media_session_id", str3);
}
for (c cVar : this.m) {
cVar.onAnalyticsEvent(analyticsEvent, map);
}
}
public final void r() {
this.T.recordBreadcrumb("reconnect", this.k);
if (this.H) {
this.B = Long.valueOf(this.U.currentTimeMillis());
}
this.D++;
c.a.r.o0.a aVar = this.v;
if (aVar != null) {
aVar.e();
aVar.f();
}
}
public final void s(String str) {
this.T.recordBreadcrumb(str, this.k);
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARNING: Unknown variable types count: 1 */
@AnyThread
public final void t(Function0<Unit> function0) {
c.a.r.c c2 = this.S.c();
if (function0 != null) {
function0 = new f0(function0);
}
c2.k.execute((Runnable) function0);
}
public final void u(Intent intent, ThumbnailEmitter thumbnailEmitter) {
if (this.V instanceof d.b) {
s("Setting screenshare " + intent + ' ' + this.w);
MediaEngineConnection mediaEngineConnection = this.w;
if (mediaEngineConnection == null) {
Log.e("RtcConnection", "MediaEngine not connected for setScreenshare.");
} else if (intent != null) {
mediaEngineConnection.a(intent, thumbnailEmitter);
} else {
mediaEngineConnection.h();
}
}
}
public final void v(State state) {
if (!m.areEqual(this.r.a, state)) {
StateChange stateChange = new StateChange(state, i());
this.r = stateChange;
for (c cVar : this.m) {
cVar.onStateChange(stateChange);
}
}
}
public final void w(long j2, float f) {
this.X.put(Long.valueOf(j2), Float.valueOf(f));
MediaEngineConnection mediaEngineConnection = this.w;
if (mediaEngineConnection != null) {
mediaEngineConnection.e(j2, f);
}
}
public final void x(Long l) {
MediaSinkWantsManager mediaSinkWantsManager = this.F;
if (mediaSinkWantsManager != null) {
mediaSinkWantsManager.b(new j(mediaSinkWantsManager, l));
}
}
}