package com.google.android.gms.internal.ads;

import android.os.Handler;
import android.os.RemoteException;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.WeakHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes2.dex */
public final /* synthetic */ class ru implements x60, l11, zk1, c2, vp1, j8, vb, uh1, fi1, h30, s7.b, t7.b, com.google.android.gms.ads.nativead.e, zu1, bj0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f16224a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final Object f16225b;

    public ru() {
        this.f16224a = 13;
        this.f16225b = new ArrayDeque();
    }

    public static ru c(kq1 kq1Var) {
        return new ru(new jc1(kq1Var, 12));
    }

    @Override // com.google.android.gms.internal.ads.c2
    public final long a(long j10) {
        y2 y2Var = (y2) this.f16225b;
        y2Var.getClass();
        String str = bb1.f9474a;
        return Math.max(0L, Math.min((j10 * ((long) y2Var.f18643e)) / 1000000, y2Var.f18648j - 1));
    }

    @Override // com.google.android.gms.internal.ads.j8
    public final void b(byte[] bArr, int i10, int i11, g7.h hVar) {
        ad0 ad0VarC;
        p01 p01Var = (p01) this.f16225b;
        p01Var.w(i10 + i11, bArr);
        p01Var.C(i10);
        ArrayList arrayList = new ArrayList();
        while (p01Var.y() > 0) {
            ih1.e0("Incomplete Mp4Webvtt Top Level box header found.", p01Var.y() >= 8);
            int iB = p01Var.b() - 8;
            if (p01Var.b() == 1987343459) {
                CharSequence charSequenceZzc = null;
                gc0 gc0VarA = null;
                while (iB > 0) {
                    ih1.e0("Incomplete vtt cue box header found.", iB >= 8);
                    int iB2 = p01Var.b();
                    int iB3 = p01Var.b();
                    int i12 = iB - 8;
                    int i13 = iB2 - 8;
                    byte[] bArr2 = p01Var.f15225a;
                    int i14 = p01Var.f15226b;
                    String str = bb1.f9474a;
                    String str2 = new String(bArr2, i14, i13, StandardCharsets.UTF_8);
                    p01Var.E(i13);
                    if (iB3 == 1937011815) {
                        w9 w9Var = new w9();
                        x9.a(str2, w9Var);
                        gc0VarA = w9Var.a();
                    } else if (iB3 == 1885436268) {
                        charSequenceZzc = x9.zzc(null, str2.trim(), Collections.emptyList());
                    }
                    iB = i12 - i13;
                }
                if (charSequenceZzc == null) {
                    charSequenceZzc = "";
                }
                if (gc0VarA != null) {
                    gc0VarA.a(charSequenceZzc);
                    ad0VarC = gc0VarA.c();
                } else {
                    Pattern pattern = x9.f18366a;
                    w9 w9Var2 = new w9();
                    w9Var2.f17935c = charSequenceZzc;
                    ad0VarC = w9Var2.a().c();
                }
                arrayList.add(ad0VarC);
            } else {
                p01Var.E(iB);
            }
        }
        hVar.mo2zza(new f8(arrayList, -9223372036854775807L, -9223372036854775807L));
    }

    public final void d(long j10, long j11, long j12) throws zzaus {
        int[] iArr = {1857962504, 67802545, 822753858, 1178641841, 1658857550, -1514359837, 393474692, 1520223205, 452867621};
        int i10 = iArr[0];
        int i11 = iArr[1];
        int i12 = iArr[2];
        int i13 = iArr[3];
        int i14 = iArr[4];
        int i15 = iArr[5];
        int i16 = iArr[6];
        int i17 = iArr[7];
        int iA = defpackage.e.a((i11 & (~i10)) | i12, (i10 & i13) | i14, i15, i16);
        ud udVar = new ud(j10, j11, j12);
        ArrayDeque arrayDeque = (ArrayDeque) this.f16225b;
        if (arrayDeque.size() >= ((i17 % 452867621) ^ iA)) {
            throw new zzaus();
        }
        arrayDeque.push(udVar);
    }

    public final /* synthetic */ void e(long j10, p01 p01Var) {
        int i10 = this.f16224a;
        Object obj = this.f16225b;
        switch (i10) {
            case 7:
                za2.i(j10, p01Var, ((d7) obj).G);
                break;
            case 8:
            default:
                za2.v(j10, p01Var, ((kb) obj).f13205b);
                break;
            case 9:
                za2.i(j10, p01Var, (u3[]) ((eb) obj).f10743d);
                break;
        }
    }

    public final void f(long j10, boolean z10) {
        u30 u30Var = ((n50) this.f16225b).f14448k;
        if (u30Var != null) {
            u30Var.d(j10, z10);
        }
    }

    public final void g(gc gcVar, lc lcVar, bv bvVar) {
        int i10;
        synchronized (gcVar.f11699e) {
            i10 = 1;
            gcVar.f11702h = true;
        }
        gcVar.a("post-response");
        ((bc) ((Executor) this.f16225b)).f9483a.post(new m1(gcVar, lcVar, bvVar, i10));
    }

    public final ud h() {
        return (ud) Optional.ofNullable((ud) ((ArrayDeque) this.f16225b).peek()).orElseThrow(td.f16858b);
    }

    public final Object i(FileInputStream fileInputStream) {
        switch (this.f16224a) {
            case 2:
                try {
                    return jt1.a(fileInputStream);
                } catch (IOException e10) {
                    throw new zzgcw("Cannot read bytes.", e10);
                }
            default:
                try {
                    bc2 bc2VarO = ((cb2) ((wb2) this.f16225b)).o();
                    ua2 ua2Var = ua2.f17195b;
                    int i10 = fa2.f11138a;
                    ua2 ua2Var2 = ua2.f17196c;
                    bb2 bb2Var = (bb2) bc2VarO;
                    bb2Var.getClass();
                    ma2 ma2VarD = ma2.d(fileInputStream);
                    cb2 cb2VarL = cb2.l(bb2Var.f9482a, ma2VarD, ua2Var2);
                    ma2VarD.j(0);
                    if (cb2.y(cb2VarL, true)) {
                        return cb2VarL;
                    }
                    throw new zzicg(new zziee().getMessage());
                } catch (zzicg e11) {
                    throw new zzgcw("Cannot read proto.", e11);
                }
        }
    }

    public final void j(int i10, boolean z10) {
        if (z10) {
            ((e.t0) this.f16225b).d(i10);
        }
    }

    public final void k(gc gcVar, zzash zzashVar) {
        gcVar.a("post-error");
        ((bc) ((Executor) this.f16225b)).f9483a.post(new m1(gcVar, new lc(zzashVar), null, 1));
    }

    public final void l(mj2 mj2Var) {
        CopyOnWriteArrayList<p> copyOnWriteArrayList = (CopyOnWriteArrayList) this.f16225b;
        for (p pVar : copyOnWriteArrayList) {
            if (pVar.f15215b == mj2Var) {
                pVar.f15216c = true;
                copyOnWriteArrayList.remove(pVar);
            }
        }
    }

    public final jf m() {
        return new jf(((e.t0) this.f16225b).f());
    }

    public final List n(CharSequence charSequence) {
        charSequence.getClass();
        Iterator itB = ((tq1) this.f16225b).b(this, charSequence);
        ArrayList arrayList = new ArrayList();
        while (itB.hasNext()) {
            arrayList.add((String) itB.next());
        }
        return Collections.unmodifiableList(arrayList);
    }

    @Override // com.google.android.gms.internal.ads.h30
    public final /* synthetic */ void zza(Object obj) {
        int i10 = this.f16224a;
        Object obj2 = this.f16225b;
        switch (i10) {
            case 18:
                dv dvVar = (dv) obj2;
                dvVar.getClass();
                if (((tu) obj).m()) {
                    dvVar.f10532e = 1;
                }
                break;
            case 19:
                b30.f9364f.execute(new bv(this, (tu) obj, 0));
                break;
            default:
                ((zf0) obj).m((mc0) obj2);
                break;
        }
    }

    @Override // com.google.android.gms.internal.ads.uh1
    public final void zzb(int i10, long j10, String str) {
        ((ch1) this.f16225b).e(i10, System.currentTimeMillis() - j10, null, null, str);
    }

    public /* synthetic */ ru(Object obj, int i10) {
        this.f16224a = i10;
        this.f16225b = obj;
    }

    public ru(int i10) {
        this.f16224a = i10;
        if (i10 == 8) {
            this.f16225b = new p01();
            return;
        }
        if (i10 == 14) {
            this.f16225b = new e.t0(5);
        } else if (i10 != 24) {
            this.f16225b = new CopyOnWriteArrayList();
        } else {
            this.f16225b = new WeakHashMap();
        }
    }

    @Override // com.google.android.gms.internal.ads.l11, com.google.android.gms.internal.ads.zu1
    /* JADX INFO: renamed from: zzb */
    public final void mo3zzb(Object obj) {
        switch (this.f16224a) {
            case 1:
                ya0 ya0Var = (ya0) obj;
                v81 v81Var = (v81) this.f16225b;
                synchronized (v81Var) {
                    try {
                        ya0 ya0Var2 = v81Var.zza;
                        if (ya0Var2 != null) {
                            ya0Var2.e();
                        }
                        v81Var.zza = ya0Var;
                        ya0Var.c(v81Var);
                        v81Var.f17565f.f(new za0(ya0Var, v81Var, v81Var.f17565f, v81Var.f17567h));
                        ya0Var.a();
                    } catch (Throwable th) {
                        throw th;
                    }
                    break;
                }
                return;
            case 27:
                ga0 ga0Var = (ga0) this.f16225b;
                qe1 qe1Var = ga0Var.f11670g;
                eb1 eb1Var = ga0Var.f11668e;
                wa1 wa1Var = ga0Var.f11669f;
                ga0Var.f11671h.a(true == m7.n.C.f30469h.i(ga0Var.f11664a) ? 2 : 1, qe1Var.zzb(eb1Var, wa1Var, false, "", (String) obj, wa1Var.f17975c, null, null));
                return;
            default:
                ((sd0) this.f16225b).f16416a.zza();
                return;
        }
    }

    public ru(Handler handler) {
        this.f16224a = 12;
        this.f16225b = new bc(this, handler);
    }

    @Override // com.google.android.gms.internal.ads.zu1
    public final void zza(Throwable th) {
    }

    public ru(ng ngVar, bh1 bh1Var) {
        this.f16224a = 16;
        this.f16225b = bh1Var;
        Objects.requireNonNull(ngVar);
    }

    @Override // com.google.android.gms.internal.ads.vb
    public final long zza() {
        return ((ByteBuffer) this.f16225b).capacity();
    }

    public ru(gr grVar) {
        this.f16224a = 23;
        this.f16225b = grVar;
        try {
            grVar.zzr();
        } catch (RemoteException unused) {
        }
    }

    @Override // com.google.android.gms.internal.ads.x60
    /* JADX INFO: renamed from: zza, reason: collision with other method in class */
    public final void mo4zza() {
        switch (this.f16224a) {
            case 0:
                x4.d dVar = (x4.d) this.f16225b;
                dVar.getClass();
                m7.n.C.f30472k.getClass();
                long jCurrentTimeMillis = System.currentTimeMillis();
                long j10 = dVar.f34720a;
                ArrayList arrayList = (ArrayList) dVar.f34723d;
                arrayList.add(Long.valueOf(jCurrentTimeMillis - j10));
                String strValueOf = String.valueOf(arrayList.get(0));
                StringBuilder sb = new StringBuilder(strValueOf.length() + 52);
                sb.append("LoadNewJavascriptEngine(onEngLoaded) latency is ");
                sb.append(strValueOf);
                sb.append(" ms.");
                p7.l0.g(sb.toString());
                p7.r0.f31763l.postDelayed(new xu((dv) dVar.f34722c, (cv) dVar.f34724e, (tu) dVar.f34721b, arrayList, j10, 1), ((Integer) n7.y.f31093e.f31096c.b(ao.f8811d)).intValue());
                return;
            default:
                v81 v81Var = (v81) this.f16225b;
                synchronized (v81Var) {
                    v81Var.zza = null;
                    break;
                }
                return;
        }
    }

    public ru(cv cvVar) {
        this.f16224a = 19;
        Objects.requireNonNull(cvVar);
        this.f16225b = cvVar;
    }

    public ru(ow owVar, bu buVar) {
        this.f16224a = 20;
        this.f16225b = buVar;
        Objects.requireNonNull(owVar);
    }

    public ru(ox oxVar, gx gxVar) {
        this.f16224a = 21;
        this.f16225b = gxVar;
        Objects.requireNonNull(oxVar);
    }

    public ru(ga0 ga0Var) {
        this.f16224a = 27;
        Objects.requireNonNull(ga0Var);
        this.f16225b = ga0Var;
    }

    public ru(sd0 sd0Var) {
        this.f16224a = 28;
        Objects.requireNonNull(sd0Var);
        this.f16225b = sd0Var;
    }

    public ru(v81 v81Var) {
        this.f16224a = 1;
        Objects.requireNonNull(v81Var);
        this.f16225b = v81Var;
    }

    public ru(tq1 tq1Var) {
        this.f16224a = 4;
        this.f16225b = tq1Var;
    }

    public ru(ByteBuffer byteBuffer) {
        this.f16224a = 11;
        this.f16225b = byteBuffer.slice();
    }

    @Override // com.google.android.gms.internal.ads.uh1
    public final void zza(int i10, long j10) {
        ((ch1) this.f16225b).b(i10, System.currentTimeMillis() - j10);
    }

    @Override // com.google.android.gms.internal.ads.vb
    public final void zzb(MessageDigest[] messageDigestArr, long j10, int i10) {
        ByteBuffer byteBufferSlice;
        ByteBuffer byteBuffer = (ByteBuffer) this.f16225b;
        synchronized (byteBuffer) {
            int i11 = (int) j10;
            byteBuffer.position(i11);
            byteBuffer.limit(i11 + i10);
            byteBufferSlice = byteBuffer.slice();
        }
        for (MessageDigest messageDigest : messageDigestArr) {
            byteBufferSlice.position(0);
            messageDigest.update(byteBufferSlice);
        }
    }
}
