package C0;

import A1.H;
import B0.A;
import L0.C;
import android.content.Context;
import android.media.metrics.PlaybackMetrics;
import android.media.metrics.PlaybackSession;
import android.media.metrics.TrackChangeEvent;
import android.os.SystemClock;
import android.util.Pair;
import java.util.HashMap;
import java.util.concurrent.Executor;
import u0.C1579o;
import u0.C1584u;
import u0.G;
import u0.P;
import u0.Q;
import u0.S;
import x0.AbstractC1709a;
import x0.v;

/* JADX INFO: loaded from: classes.dex */
public final class k {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public int f1123A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public boolean f1124B;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f1125a;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final h f1127c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final PlaybackSession f1128d;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public String f1133j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public PlaybackMetrics.Builder f1134k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f1135l;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public G f1138o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public H f1139p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public H f1140q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public H f1141r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public C1579o f1142s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public C1579o f1143t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public C1579o f1144u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f1145v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public int f1146w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f1147x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f1148y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public int f1149z;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Executor f1126b = AbstractC1709a.q();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Q f1130f = new Q();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final P f1131g = new P();
    public final HashMap i = new HashMap();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final HashMap f1132h = new HashMap();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final long f1129e = SystemClock.elapsedRealtime();

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f1136m = 0;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f1137n = 0;

    public k(Context context, PlaybackSession playbackSession) {
        this.f1125a = context.getApplicationContext();
        this.f1128d = playbackSession;
        h hVar = new h();
        this.f1127c = hVar;
        hVar.f1119d = this;
    }

    public final boolean a(H h8) {
        String str;
        if (h8 == null) {
            return false;
        }
        String str2 = (String) h8.f67t;
        h hVar = this.f1127c;
        synchronized (hVar) {
            str = hVar.f1121f;
        }
        return str2.equals(str);
    }

    public final void b() {
        PlaybackMetrics.Builder builder = this.f1134k;
        if (builder != null && this.f1124B) {
            builder.setAudioUnderrunCount(this.f1123A);
            this.f1134k.setVideoFramesDropped(this.f1148y);
            this.f1134k.setVideoFramesPlayed(this.f1149z);
            Long l8 = (Long) this.f1132h.get(this.f1133j);
            this.f1134k.setNetworkTransferDurationMillis(l8 == null ? 0L : l8.longValue());
            Long l9 = (Long) this.i.get(this.f1133j);
            this.f1134k.setNetworkBytesRead(l9 == null ? 0L : l9.longValue());
            this.f1134k.setStreamSource((l9 == null || l9.longValue() <= 0) ? 0 : 1);
            this.f1126b.execute(new A(this, 5, this.f1134k.build()));
        }
        this.f1134k = null;
        this.f1133j = null;
        this.f1123A = 0;
        this.f1148y = 0;
        this.f1149z = 0;
        this.f1142s = null;
        this.f1143t = null;
        this.f1144u = null;
        this.f1124B = false;
    }

    public final void c(S s8, C c3) {
        int iB;
        PlaybackMetrics.Builder builder = this.f1134k;
        if (c3 == null || (iB = s8.b(c3.f3625a)) == -1) {
            return;
        }
        P p3 = this.f1131g;
        int i = 0;
        s8.f(iB, p3, false);
        int i5 = p3.f17177c;
        Q q8 = this.f1130f;
        s8.n(i5, q8);
        C1584u c1584u = q8.f17186c.f17396b;
        if (c1584u != null) {
            int iE = v.E(c1584u.f17384a, c1584u.f17385b);
            i = iE != 0 ? iE != 1 ? iE != 2 ? 1 : 4 : 5 : 3;
        }
        builder.setStreamType(i);
        if (q8.f17195m != -9223372036854775807L && !q8.f17193k && !q8.i && !q8.a()) {
            builder.setMediaDurationMillis(v.W(q8.f17195m));
        }
        builder.setPlaybackType(q8.a() ? 2 : 1);
        this.f1124B = true;
    }

    public final void d(a aVar, String str) {
        C c3 = aVar.f1085d;
        if ((c3 == null || !c3.b()) && str.equals(this.f1133j)) {
            b();
        }
        this.f1132h.remove(str);
        this.i.remove(str);
    }

    public final void e(int i, long j8, C1579o c1579o, int i5) {
        int i8;
        int i9 = 2;
        TrackChangeEvent.Builder timeSinceCreatedMillis = j.l(i).setTimeSinceCreatedMillis(j8 - this.f1129e);
        if (c1579o != null) {
            timeSinceCreatedMillis.setTrackState(1);
            if (i5 != 1) {
                i8 = 3;
                if (i5 != 2) {
                    i8 = i5 != 3 ? 1 : 4;
                }
            } else {
                i8 = 2;
            }
            timeSinceCreatedMillis.setTrackChangeReason(i8);
            String str = c1579o.f17357m;
            if (str != null) {
                timeSinceCreatedMillis.setContainerMimeType(str);
            }
            String str2 = c1579o.f17358n;
            if (str2 != null) {
                timeSinceCreatedMillis.setSampleMimeType(str2);
            }
            String str3 = c1579o.f17355k;
            if (str3 != null) {
                timeSinceCreatedMillis.setCodecName(str3);
            }
            int i10 = c1579o.f17354j;
            if (i10 != -1) {
                timeSinceCreatedMillis.setBitrate(i10);
            }
            int i11 = c1579o.f17365u;
            if (i11 != -1) {
                timeSinceCreatedMillis.setWidth(i11);
            }
            int i12 = c1579o.f17366v;
            if (i12 != -1) {
                timeSinceCreatedMillis.setHeight(i12);
            }
            int i13 = c1579o.D;
            if (i13 != -1) {
                timeSinceCreatedMillis.setChannelCount(i13);
            }
            int i14 = c1579o.f17337E;
            if (i14 != -1) {
                timeSinceCreatedMillis.setAudioSampleRate(i14);
            }
            String str4 = c1579o.f17349d;
            if (str4 != null) {
                int i15 = v.f18553a;
                String[] strArrSplit = str4.split("-", -1);
                Pair pairCreate = Pair.create(strArrSplit[0], strArrSplit.length >= 2 ? strArrSplit[1] : null);
                timeSinceCreatedMillis.setLanguage((String) pairCreate.first);
                Object obj = pairCreate.second;
                if (obj != null) {
                    timeSinceCreatedMillis.setLanguageRegion((String) obj);
                }
            }
            float f3 = c1579o.f17367w;
            if (f3 != -1.0f) {
                timeSinceCreatedMillis.setVideoFrameRate(f3);
            }
        } else {
            timeSinceCreatedMillis.setTrackState(0);
        }
        this.f1124B = true;
        this.f1126b.execute(new A(this, i9, timeSinceCreatedMillis.build()));
    }
}
