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

import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaFormat;
import android.media.metrics.LogSessionId;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.Trace;
import androidx.annotation.CallSuper;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.PlaybackException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes2.dex */
public abstract class wn2 extends pf2 {
    public static final byte[] O0 = {0, 0, 1, 103, 66, -64, 11, -38, 37, -112, 0, 0, 1, 104, -50, 15, 19, 32, 0, 0, 1, 101, -120, -124, 13, -50, 113, 24, -96, 0, 47, -65, 28, 49, -61, 39, 93, 120};
    public boolean A0;
    public boolean B0;
    public boolean C0;
    public long D0;
    public boolean E0;
    public boolean F0;
    public boolean G0;
    public ug2 H0;
    public vn2 I0;
    public long J0;
    public boolean K0;
    public boolean L0;
    public boolean M0;
    public long N0;
    public final pn2 Q;
    public final xn2 R;
    public final float S;
    public final fe2 T;
    public final fe2 U;
    public final fe2 V;
    public final kn2 W;
    public final MediaCodec.BufferInfo X;
    public final ArrayDeque Y;
    public final um2 Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public final AtomicInteger f18124a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public zn2 f18125b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public dj2 f18126c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final long f18127d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public float f18128e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public float f18129f0;

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

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public float f18131h0;

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

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

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

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

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

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public long f18137n0;

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

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public long f18139p0;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public int f18148y0;
    public int z0;

    @Nullable
    private ArrayDeque zzB;

    @Nullable
    private zzuq zzC;

    @Nullable
    private tn2 zzD;

    @Nullable
    private ByteBuffer zzP;

    @Nullable
    private zn2 zzn;

    @Nullable
    private ym2 zzp;

    @Nullable
    private ym2 zzq;

    @Nullable
    private MediaCrypto zzs;

    @Nullable
    private rn2 zzw;

    @Nullable
    private zn2 zzx;

    @Nullable
    private MediaFormat zzy;

    public wn2(int i10, pn2 pn2Var, xn2 xn2Var, float f10) {
        super(i10);
        this.Q = pn2Var;
        xn2Var.getClass();
        this.R = xn2Var;
        this.S = f10;
        this.f18124a0 = new AtomicInteger();
        this.T = new fe2(0);
        this.U = new fe2(0);
        this.V = new fe2(2);
        kn2 kn2Var = new kn2(2);
        kn2Var.f13329i = 32;
        this.W = kn2Var;
        this.X = new MediaCodec.BufferInfo();
        this.f18128e0 = 1.0f;
        this.f18129f0 = 1.0f;
        this.f18127d0 = -9223372036854775807L;
        this.Y = new ArrayDeque();
        this.I0 = vn2.f17719f;
        kn2Var.i(0);
        kn2Var.zzc.order(ByteOrder.nativeOrder());
        um2 um2Var = new um2();
        um2Var.f17332a = i80.f12407a;
        um2Var.f17334c = 0;
        um2Var.f17333b = 2;
        this.Z = um2Var;
        this.f18131h0 = -1.0f;
        this.f18132i0 = 0;
        this.f18147x0 = 0;
        this.f18140q0 = -1;
        this.f18141r0 = -1;
        this.f18139p0 = -9223372036854775807L;
        this.D0 = -9223372036854775807L;
        this.J0 = -9223372036854775807L;
        this.f18137n0 = -9223372036854775807L;
        this.f18148y0 = 0;
        this.z0 = 0;
        this.H0 = new ug2();
        this.M0 = false;
        this.N0 = 0L;
    }

    private final boolean zzbj(@Nullable zn2 zn2Var) throws zziw {
        if (this.zzw != null && this.z0 != 3 && this.f15399g != 0) {
            float f10 = this.f18129f0;
            zn2Var.getClass();
            float fD0 = d0(f10, zn2Var, m());
            float f11 = this.f18131h0;
            if (f11 != fD0) {
                if (fD0 == -1.0f) {
                    o0();
                    return false;
                }
                if (f11 != -1.0f || fD0 > this.S) {
                    Bundle bundle = new Bundle();
                    bundle.putFloat("operating-rate", fD0);
                    rn2 rn2Var = this.zzw;
                    rn2Var.getClass();
                    rn2Var.c(bundle);
                    this.f18131h0 = fD0;
                }
            }
        }
        return true;
    }

    /* JADX WARN: Code restructure failed: missing block: B:15:0x003d, code lost:
    
        if (r7 >= r5) goto L16;
     */
    @Override // com.google.android.gms.internal.ads.pf2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void H(zn2[] zn2VarArr, long j10, long j11, cp2 cp2Var) {
        if (this.I0.f17722c == -9223372036854775807L) {
            q0(new vn2(-9223372036854775807L, j10, j11));
            if (this.L0) {
                h0();
                return;
            }
            return;
        }
        ArrayDeque arrayDeque = this.Y;
        if (arrayDeque.isEmpty()) {
            long j12 = this.D0;
            if (j12 != -9223372036854775807L) {
                long j13 = this.J0;
                if (j13 != -9223372036854775807L) {
                }
            }
            q0(new vn2(-9223372036854775807L, j10, j11));
            if (this.I0.f17722c != -9223372036854775807L) {
                h0();
                return;
            }
            return;
        }
        arrayDeque.add(new vn2(this.D0, j10, j11));
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x01be  */
    /* JADX WARN: Removed duplicated region for block: B:107:0x01cc  */
    /* JADX WARN: Removed duplicated region for block: B:108:0x01ce  */
    /* JADX WARN: Removed duplicated region for block: B:133:0x0226 A[Catch: Exception -> 0x0108, TryCatch #8 {Exception -> 0x0108, blocks: (B:66:0x00fe, B:79:0x014b, B:81:0x015e, B:82:0x0179, B:84:0x0181, B:86:0x0189, B:88:0x0193, B:90:0x019b, B:92:0x01a3, B:96:0x01ae, B:98:0x01b4, B:102:0x01bf, B:104:0x01c3, B:129:0x021a, B:131:0x0221, B:133:0x0226, B:134:0x0234, B:109:0x01d0, B:111:0x01d8, B:113:0x01e0, B:115:0x01e8, B:117:0x01f0, B:119:0x01f8, B:121:0x0200, B:123:0x020a, B:125:0x0214), top: B:184:0x00fe }] */
    /* JADX WARN: Removed duplicated region for block: B:154:0x0287 A[Catch: zzuq -> 0x028a, TryCatch #2 {zzuq -> 0x028a, blocks: (B:152:0x026e, B:154:0x0287, B:158:0x0292, B:161:0x029c, B:162:0x029e, B:157:0x028c, B:163:0x029f, B:165:0x02a5, B:166:0x02b2), top: B:174:0x0097 }] */
    /* JADX WARN: Removed duplicated region for block: B:157:0x028c A[Catch: zzuq -> 0x028a, TryCatch #2 {zzuq -> 0x028a, blocks: (B:152:0x026e, B:154:0x0287, B:158:0x0292, B:161:0x029c, B:162:0x029e, B:157:0x028c, B:163:0x029f, B:165:0x02a5, B:166:0x02b2), top: B:174:0x0097 }] */
    /* JADX WARN: Removed duplicated region for block: B:160:0x0298  */
    /* JADX WARN: Removed duplicated region for block: B:195:0x029c A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:81:0x015e A[Catch: Exception -> 0x0108, TryCatch #8 {Exception -> 0x0108, blocks: (B:66:0x00fe, B:79:0x014b, B:81:0x015e, B:82:0x0179, B:84:0x0181, B:86:0x0189, B:88:0x0193, B:90:0x019b, B:92:0x01a3, B:96:0x01ae, B:98:0x01b4, B:102:0x01bf, B:104:0x01c3, B:129:0x021a, B:131:0x0221, B:133:0x0226, B:134:0x0234, B:109:0x01d0, B:111:0x01d8, B:113:0x01e0, B:115:0x01e8, B:117:0x01f0, B:119:0x01f8, B:121:0x0200, B:123:0x020a, B:125:0x0214), top: B:184:0x00fe }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x01ad  */
    /* JADX WARN: Removed duplicated region for block: B:98:0x01b4 A[Catch: Exception -> 0x0108, TryCatch #8 {Exception -> 0x0108, blocks: (B:66:0x00fe, B:79:0x014b, B:81:0x015e, B:82:0x0179, B:84:0x0181, B:86:0x0189, B:88:0x0193, B:90:0x019b, B:92:0x01a3, B:96:0x01ae, B:98:0x01b4, B:102:0x01bf, B:104:0x01c3, B:129:0x021a, B:131:0x0221, B:133:0x0226, B:134:0x0234, B:109:0x01d0, B:111:0x01d8, B:113:0x01e0, B:115:0x01e8, B:117:0x01f0, B:119:0x01f8, B:121:0x0200, B:123:0x020a, B:125:0x0214), top: B:184:0x00fe }] */
    /* JADX WARN: Type inference failed for: r0v39, types: [com.google.android.gms.internal.ads.rn2] */
    /* JADX WARN: Type inference failed for: r10v11 */
    /* JADX WARN: Type inference failed for: r10v12 */
    /* JADX WARN: Type inference failed for: r10v13 */
    /* JADX WARN: Type inference failed for: r10v14, types: [java.lang.StringBuilder] */
    /* JADX WARN: Type inference failed for: r10v15 */
    /* JADX WARN: Type inference failed for: r10v16 */
    /* JADX WARN: Type inference failed for: r10v17 */
    /* JADX WARN: Type inference failed for: r10v18 */
    /* JADX WARN: Type inference failed for: r10v19 */
    /* JADX WARN: Type inference failed for: r10v20 */
    /* JADX WARN: Type inference failed for: r10v21 */
    /* JADX WARN: Type inference failed for: r10v22 */
    /* JADX WARN: Type inference failed for: r10v3, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r10v6 */
    /* JADX WARN: Type inference failed for: r10v7 */
    /* JADX WARN: Type inference failed for: r1v6, types: [java.util.ArrayDeque] */
    /* JADX WARN: Type inference failed for: r21v0, types: [com.google.android.gms.internal.ads.pf2, com.google.android.gms.internal.ads.wn2] */
    /* JADX WARN: Type inference failed for: r9v10 */
    /* JADX WARN: Type inference failed for: r9v11 */
    /* JADX WARN: Type inference failed for: r9v12 */
    /* JADX WARN: Type inference failed for: r9v15, types: [com.google.android.gms.internal.ads.un2] */
    /* JADX WARN: Type inference failed for: r9v17 */
    /* JADX WARN: Type inference failed for: r9v18 */
    /* JADX WARN: Type inference failed for: r9v2 */
    /* JADX WARN: Type inference failed for: r9v20 */
    /* JADX WARN: Type inference failed for: r9v23 */
    /* JADX WARN: Type inference failed for: r9v24 */
    /* JADX WARN: Type inference failed for: r9v25 */
    /* JADX WARN: Type inference failed for: r9v26 */
    /* JADX WARN: Type inference failed for: r9v27 */
    /* JADX WARN: Type inference failed for: r9v3, types: [com.google.android.gms.internal.ads.tn2] */
    /* JADX WARN: Type inference failed for: r9v6 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void I() throws zziw {
        zn2 zn2Var;
        String str;
        zn2 zn2Var2;
        zn2 zn2Var3;
        ?? r92;
        zn2 zn2Var4;
        ?? r10;
        zzuq zzuqVar;
        zn2 zn2Var5;
        zn2 zn2Var6;
        float fD0;
        long jElapsedRealtime;
        on2 on2VarZzaf;
        int i10;
        ?? r102;
        zn2 zn2Var7;
        zn2 zn2Var8;
        ?? sb;
        ?? un2Var;
        int i11;
        zn2 zn2Var9;
        ?? r93;
        if (this.zzw != null || this.f18143t0 || (zn2Var = this.zzn) == null) {
            return;
        }
        if (J(zn2Var)) {
            this.f18143t0 = false;
            k0();
            String str2 = zn2Var.zzo;
            boolean zEquals = MimeTypes.AUDIO_AAC.equals(str2);
            kn2 kn2Var = this.W;
            if (zEquals || MimeTypes.AUDIO_MPEG.equals(str2) || MimeTypes.AUDIO_OPUS.equals(str2)) {
                kn2Var.f13329i = 32;
            } else {
                kn2Var.f13329i = 1;
            }
            this.f18143t0 = true;
            return;
        }
        ym2 ym2Var = this.zzq;
        this.zzp = ym2Var;
        if (ym2Var != null) {
            ((en2) ym2Var).zza();
        }
        try {
            zn2 zn2Var10 = this.zzn;
            zn2Var10.getClass();
            MediaCrypto mediaCrypto = null;
            if (this.zzB == null) {
                try {
                    ArrayList arrayListZ = Z(this.R, zn2Var10);
                    arrayListZ.isEmpty();
                    this.zzB = new ArrayDeque();
                    if (!arrayListZ.isEmpty()) {
                        this.zzB.add((tn2) arrayListZ.get(0));
                    }
                    this.zzC = null;
                } catch (zzuy e10) {
                    throw new zzuq(zn2Var10, (Throwable) e10, false, -49998);
                }
            }
            try {
                if (this.zzB.isEmpty()) {
                    throw new zzuq(zn2Var10, (Throwable) null, false, -49999);
                }
                ArrayDeque arrayDeque = this.zzB;
                arrayDeque.getClass();
                zn2 zn2Var11 = zn2Var;
                while (this.zzw == null) {
                    tn2 tn2Var = (tn2) arrayDeque.peekFirst();
                    tn2Var.getClass();
                    String str3 = tn2Var.f16954a;
                    R(zn2Var10);
                    if (!K(tn2Var)) {
                        return;
                    }
                    try {
                        this.zzD = tn2Var;
                        zn2Var6 = this.zzn;
                        zn2Var6.getClass();
                        fD0 = d0(this.f18129f0, zn2Var6, m());
                        if (fD0 <= this.S) {
                            fD0 = -1.0f;
                        }
                        this.f15398f.getClass();
                        jElapsedRealtime = SystemClock.elapsedRealtime();
                        try {
                            on2VarZzaf = zzaf(tn2Var, zn2Var6, mediaCrypto, fD0);
                            i10 = Build.VERSION.SDK_INT;
                            r102 = 31;
                        } catch (Exception e11) {
                            e = e11;
                            str = str3;
                            zn2Var2 = zn2Var11;
                            zn2Var3 = zn2Var10;
                            r92 = tn2Var;
                            r10 = str;
                            zn2Var4 = zn2Var2;
                            vt0.zzd("MediaCodecRenderer", "Failed to initialize decoder: ".concat(r10), e);
                            arrayDeque.removeFirst();
                            zn2 zn2Var12 = zn2Var3;
                            zzuq zzuqVar2 = new zzuq(zn2Var12, (Throwable) e, false, (tn2) r92);
                            g0(zzuqVar2);
                            zzuqVar = this.zzC;
                            if (zzuqVar == null) {
                            }
                            if (arrayDeque.isEmpty()) {
                            }
                        }
                    } catch (Exception e12) {
                        e = e12;
                        str = str3;
                        zn2Var2 = zn2Var11;
                        zn2Var3 = zn2Var10;
                    }
                    try {
                        if (i10 >= 31) {
                            try {
                                mk2 mk2Var = this.f15397e;
                                mk2Var.getClass();
                                try {
                                    LogSessionId logSessionIdA = mk2Var.a();
                                    zn2Var7 = zn2Var11;
                                    try {
                                        boolean zEquals2 = logSessionIdA.equals(LogSessionId.LOG_SESSION_ID_NONE);
                                        r93 = zEquals2;
                                        r102 = logSessionIdA;
                                        zn2Var9 = zn2Var7;
                                        if (!zEquals2) {
                                            MediaFormat mediaFormat = on2VarZzaf.f15118b;
                                            zn2Var3 = zn2Var10;
                                            try {
                                                String stringId = logSessionIdA.getStringId();
                                                mediaFormat.setString("log-session-id", stringId);
                                                un2Var = mediaFormat;
                                                sb = stringId;
                                                zn2Var8 = zn2Var7;
                                            } catch (Exception e13) {
                                                e = e13;
                                                r92 = tn2Var;
                                                r10 = str3;
                                                zn2Var4 = zn2Var7;
                                                vt0.zzd("MediaCodecRenderer", "Failed to initialize decoder: ".concat(r10), e);
                                                arrayDeque.removeFirst();
                                                zn2 zn2Var122 = zn2Var3;
                                                zzuq zzuqVar22 = new zzuq(zn2Var122, (Throwable) e, false, (tn2) r92);
                                                g0(zzuqVar22);
                                                zzuqVar = this.zzC;
                                                if (zzuqVar == null) {
                                                }
                                                if (arrayDeque.isEmpty()) {
                                                }
                                            }
                                        }
                                        sb = new StringBuilder(str3.length() + 12);
                                        sb.append("createCodec:");
                                        sb.append(str3);
                                        Trace.beginSection(sb.toString());
                                        ?? B = this.Q.b(on2VarZzaf);
                                        this.zzw = B;
                                        un2Var = new un2(this);
                                        this.f18138o0 = B.e(un2Var);
                                        Trace.endSection();
                                        this.f15398f.getClass();
                                        long jElapsedRealtime2 = SystemClock.elapsedRealtime();
                                        if (!tn2Var.a(zn2Var6)) {
                                            Object[] objArr = {zn2.zze(zn2Var6), str3};
                                            String str4 = bb1.f9474a;
                                            vt0.c(String.format(Locale.US, "Format exceeds selected codec's capabilities [%s, %s]", objArr));
                                        }
                                        this.f18131h0 = fD0;
                                        this.zzx = zn2Var6;
                                        if (i10 <= 25 || !"OMX.Exynos.avc.dec.secure".equals(str3)) {
                                            i11 = 0;
                                            this.f18132i0 = i11;
                                            this.f18133j0 = i10 == 29 && "c2.android.aac.decoder".equals(str3);
                                            if (i10 <= 25 || !"OMX.rk.video_decoder.avc".equals(str3)) {
                                                boolean z10 = (i10 > 29 && ("OMX.broadcom.video_decoder.tunnel".equals(str3) || "OMX.broadcom.video_decoder.tunnel.secure".equals(str3) || "OMX.bcm.vdec.avc.tunnel".equals(str3) || "OMX.bcm.vdec.avc.tunnel.secure".equals(str3) || "OMX.bcm.vdec.hevc.tunnel".equals(str3) || "OMX.bcm.vdec.hevc.tunnel.secure".equals(str3))) || ("Amazon".equals(Build.MANUFACTURER) && "AFTS".equals(Build.MODEL) && tn2Var.f16958e);
                                                this.f18136m0 = z10;
                                                this.zzw.getClass();
                                                if (this.f15399g == 2) {
                                                    this.f15398f.getClass();
                                                    this.f18139p0 = SystemClock.elapsedRealtime() + 1000;
                                                }
                                                try {
                                                    this.H0.f17240a++;
                                                    long j10 = jElapsedRealtime2 - jElapsedRealtime;
                                                    un2Var = tn2Var;
                                                    sb = str3;
                                                    try {
                                                        e0(str3, jElapsedRealtime2, j10);
                                                        zn2Var5 = zn2Var8;
                                                        zn2Var10 = zn2Var3;
                                                    } catch (Exception e14) {
                                                        e = e14;
                                                        r92 = un2Var;
                                                        r10 = sb;
                                                        zn2Var4 = zn2Var8;
                                                        vt0.zzd("MediaCodecRenderer", "Failed to initialize decoder: ".concat(r10), e);
                                                        arrayDeque.removeFirst();
                                                        zn2 zn2Var1222 = zn2Var3;
                                                        zzuq zzuqVar222 = new zzuq(zn2Var1222, (Throwable) e, false, (tn2) r92);
                                                        g0(zzuqVar222);
                                                        zzuqVar = this.zzC;
                                                        if (zzuqVar == null) {
                                                            this.zzC = zzuqVar222;
                                                        } else {
                                                            this.zzC = zzuqVar.a(zzuqVar222);
                                                        }
                                                        if (arrayDeque.isEmpty()) {
                                                            throw this.zzC;
                                                        }
                                                        zn2Var10 = zn2Var1222;
                                                        zn2Var5 = zn2Var4;
                                                    }
                                                } catch (Exception e15) {
                                                    e = e15;
                                                    r92 = tn2Var;
                                                    r10 = str3;
                                                    zn2Var4 = zn2Var8;
                                                    vt0.zzd("MediaCodecRenderer", "Failed to initialize decoder: ".concat(r10), e);
                                                    arrayDeque.removeFirst();
                                                    zn2 zn2Var12222 = zn2Var3;
                                                    zzuq zzuqVar2222 = new zzuq(zn2Var12222, (Throwable) e, false, (tn2) r92);
                                                    g0(zzuqVar2222);
                                                    zzuqVar = this.zzC;
                                                    if (zzuqVar == null) {
                                                    }
                                                    if (arrayDeque.isEmpty()) {
                                                    }
                                                }
                                            }
                                        } else {
                                            String str5 = Build.MODEL;
                                            if (str5.startsWith("SM-T585") || str5.startsWith("SM-A510") || str5.startsWith("SM-A520") || str5.startsWith("SM-J700")) {
                                                i11 = 2;
                                            }
                                            this.f18132i0 = i11;
                                            if (i10 == 29) {
                                                this.f18133j0 = i10 == 29 && "c2.android.aac.decoder".equals(str3);
                                                if (i10 <= 25) {
                                                    if (i10 > 29) {
                                                        this.f18136m0 = z10;
                                                        this.zzw.getClass();
                                                        if (this.f15399g == 2) {
                                                        }
                                                        this.H0.f17240a++;
                                                        long j102 = jElapsedRealtime2 - jElapsedRealtime;
                                                        un2Var = tn2Var;
                                                        sb = str3;
                                                        e0(str3, jElapsedRealtime2, j102);
                                                        zn2Var5 = zn2Var8;
                                                        zn2Var10 = zn2Var3;
                                                    } else {
                                                        this.f18136m0 = z10;
                                                        this.zzw.getClass();
                                                        if (this.f15399g == 2) {
                                                        }
                                                        this.H0.f17240a++;
                                                        long j1022 = jElapsedRealtime2 - jElapsedRealtime;
                                                        un2Var = tn2Var;
                                                        sb = str3;
                                                        e0(str3, jElapsedRealtime2, j1022);
                                                        zn2Var5 = zn2Var8;
                                                        zn2Var10 = zn2Var3;
                                                    }
                                                }
                                            }
                                        }
                                    } catch (Exception e16) {
                                        e = e16;
                                        zn2Var3 = zn2Var10;
                                        r92 = tn2Var;
                                        r10 = str3;
                                        zn2Var4 = zn2Var7;
                                        vt0.zzd("MediaCodecRenderer", "Failed to initialize decoder: ".concat(r10), e);
                                        arrayDeque.removeFirst();
                                        zn2 zn2Var122222 = zn2Var3;
                                        zzuq zzuqVar22222 = new zzuq(zn2Var122222, (Throwable) e, false, (tn2) r92);
                                        g0(zzuqVar22222);
                                        zzuqVar = this.zzC;
                                        if (zzuqVar == null) {
                                        }
                                        if (arrayDeque.isEmpty()) {
                                        }
                                    }
                                } catch (Exception e17) {
                                    e = e17;
                                    zn2Var7 = zn2Var11;
                                }
                            } catch (Exception e18) {
                                e = e18;
                                zn2Var7 = zn2Var11;
                            }
                            mediaCrypto = null;
                            zn2Var11 = zn2Var5;
                        } else {
                            zn2Var9 = zn2Var11;
                            r93 = zn2Var11;
                        }
                        sb = new StringBuilder(str3.length() + 12);
                        sb.append("createCodec:");
                        sb.append(str3);
                        Trace.beginSection(sb.toString());
                        ?? B2 = this.Q.b(on2VarZzaf);
                        this.zzw = B2;
                        un2Var = new un2(this);
                        this.f18138o0 = B2.e(un2Var);
                        Trace.endSection();
                        this.f15398f.getClass();
                        long jElapsedRealtime22 = SystemClock.elapsedRealtime();
                        if (!tn2Var.a(zn2Var6)) {
                        }
                        this.f18131h0 = fD0;
                        this.zzx = zn2Var6;
                        if (i10 <= 25) {
                            i11 = 0;
                            this.f18132i0 = i11;
                        }
                        mediaCrypto = null;
                        zn2Var11 = zn2Var5;
                    } catch (Throwable th) {
                        un2Var = tn2Var;
                        sb = str3;
                        Trace.endSection();
                        throw th;
                    }
                    zn2Var3 = zn2Var10;
                    un2Var = r93;
                    sb = r102;
                    zn2Var8 = zn2Var9;
                }
                this.zzB = mediaCrypto;
            } catch (zzuq e19) {
                e = e19;
                throw zzN(e, zn2Var, false, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
            }
        } catch (zzuq e20) {
            e = e20;
            throw zzN(e, zn2Var, false, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED);
        }
    }

    public final boolean J(zn2 zn2Var) {
        return this.zzq == null && a0(zn2Var);
    }

    public boolean K(tn2 tn2Var) {
        return true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void L() {
        try {
            rn2 rn2Var = this.zzw;
            if (rn2Var != null) {
                rn2Var.zzl();
                this.H0.f17241b++;
                tn2 tn2Var = this.zzD;
                tn2Var.getClass();
                f0(tn2Var.f16954a);
            }
        } finally {
            this.zzw = null;
            this.zzs = null;
            this.zzp = null;
            Q();
        }
    }

    public final void M() throws zziw {
        if (this.zzw == null) {
            return;
        }
        if (N()) {
            L();
            I();
        } else if (O()) {
            l0();
        } else {
            this.M0 = true;
        }
    }

    public boolean N() {
        int i10 = this.z0;
        if (i10 == 3 || (this.f18133j0 && !this.C0)) {
            return true;
        }
        if (i10 == 2) {
            try {
                ym2 ym2Var = this.zzq;
                ym2Var.getClass();
                this.zzp = ym2Var;
                this.f18148y0 = 0;
                this.z0 = 0;
            } catch (zziw e10) {
                vt0.zzd("MediaCodecRenderer", "Failed to update the DRM session, releasing the codec instead.", e10);
                return true;
            }
        }
        return false;
    }

    public boolean O() {
        return true;
    }

    public void P() {
        this.f18140q0 = -1;
        this.U.zzc = null;
        this.f18141r0 = -1;
        this.zzP = null;
        this.D0 = -9223372036854775807L;
        r0().f17724e = -9223372036854775807L;
        this.J0 = -9223372036854775807L;
        this.f18139p0 = -9223372036854775807L;
        this.B0 = false;
        this.f18137n0 = -9223372036854775807L;
        this.A0 = false;
        this.f18134k0 = false;
        this.f18135l0 = false;
        this.f18142s0 = false;
        this.f18148y0 = 0;
        this.z0 = 0;
        this.f18147x0 = this.f18146w0 ? 1 : 0;
        this.M0 = false;
        this.N0 = 0L;
    }

    public final void Q() {
        P();
        this.zzB = null;
        this.zzD = null;
        this.zzx = null;
        this.zzy = null;
        this.f18130g0 = false;
        this.C0 = false;
        this.f18131h0 = -1.0f;
        this.f18132i0 = 0;
        this.f18133j0 = false;
        this.f18136m0 = false;
        this.f18138o0 = false;
        this.f18146w0 = false;
        this.f18147x0 = 0;
    }

    public void R(zn2 zn2Var) {
    }

    public void S(fe2 fe2Var) {
    }

    public int T(fe2 fe2Var) {
        return 0;
    }

    public boolean U(fe2 fe2Var) {
        return false;
    }

    public void V(long j10) {
        this.J0 = j10;
        while (true) {
            ArrayDeque arrayDeque = this.Y;
            if (arrayDeque.isEmpty() || j10 < ((vn2) arrayDeque.peek()).f17720a) {
                return;
            }
            vn2 vn2Var = (vn2) arrayDeque.poll();
            vn2Var.getClass();
            q0(vn2Var);
            h0();
        }
    }

    public final boolean W() {
        if (this.zzn == null) {
            return false;
        }
        if (r() || this.f18141r0 >= 0) {
            return true;
        }
        if (this.f18139p0 == -9223372036854775807L) {
            return false;
        }
        this.f15398f.getClass();
        return SystemClock.elapsedRealtime() < this.f18139p0;
    }

    public final void X() throws zziw {
        zzbj(this.zzx);
    }

    public abstract int Y(xn2 xn2Var, zn2 zn2Var);

    public abstract ArrayList Z(xn2 xn2Var, zn2 zn2Var);

    /*  JADX ERROR: Type inference failed with stack overflow
        jadx.core.utils.exceptions.JadxOverflowException
        	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
        	at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
        	at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
        	at jadx.core.dex.visitors.typeinference.TypeInferenceVisitor.visit(TypeInferenceVisitor.java:77)
        */
    @Override // com.google.android.gms.internal.ads.ej2
    public void a(long r33, long r35) throws com.google.android.gms.internal.ads.zziw {
        /*
            Method dump skipped, instruction units count: 1780
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.gms.internal.ads.wn2.a(long, long):void");
    }

    public boolean a0(zn2 zn2Var) {
        return false;
    }

    public abstract vg2 b0(tn2 tn2Var, zn2 zn2Var, zn2 zn2Var2);

    public long c0(long j10, long j11) {
        long j12 = 10000;
        if (this.f15399g == 1) {
            if (B()) {
                j12 = 1000000;
            } else if (d()) {
                return 1000000L;
            }
        }
        return j12;
    }

    public abstract float d0(float f10, zn2 zn2Var, zn2[] zn2VarArr);

    @Override // com.google.android.gms.internal.ads.ej2
    public void e(float f10, float f11) throws zziw {
        this.f18128e0 = f10;
        this.f18129f0 = f11;
        zzbj(this.zzx);
    }

    public abstract void e0(String str, long j10, long j11);

    @Override // com.google.android.gms.internal.ads.pf2
    public void f(long j10, boolean z10, boolean z11) {
        ArrayDeque arrayDeque = this.Y;
        if (!arrayDeque.isEmpty()) {
            this.I0 = (vn2) arrayDeque.getLast();
        }
        arrayDeque.clear();
        if (z11) {
            this.E0 = false;
            this.F0 = false;
            if (this.f18143t0) {
                k0();
            } else if (this.zzw != null) {
                if (N()) {
                    L();
                    I();
                } else if (O()) {
                    l0();
                } else {
                    this.M0 = true;
                }
            }
            w81 w81Var = this.I0.f17723d;
            if (w81Var.b() > 0) {
                this.G0 = true;
            }
            synchronized (w81Var) {
                w81Var.f17924c = 0;
                w81Var.f17925d = 0;
                Arrays.fill(w81Var.f17923b, (Object) null);
            }
        }
    }

    public abstract void f0(String str);

    public abstract void g0(Exception exc);

    public abstract void h0();

    @Override // com.google.android.gms.internal.ads.pf2
    public void i() {
        this.zzn = null;
        q0(vn2.f17719f);
        this.Y.clear();
        if (this.f18143t0) {
            this.f18143t0 = false;
            k0();
        } else {
            if (this.zzw == null) {
                return;
            }
            if (N()) {
                L();
            } else if (O()) {
                l0();
            } else {
                this.M0 = true;
            }
        }
    }

    public abstract void i0();

    @Override // com.google.android.gms.internal.ads.pf2
    public void j() {
        try {
            this.f18143t0 = false;
            k0();
            L();
        } finally {
            this.zzq = null;
        }
    }

    public abstract void j0(fe2 fe2Var);

    public final void k0() {
        this.D0 = -9223372036854775807L;
        r0().f17724e = -9223372036854775807L;
        this.J0 = -9223372036854775807L;
        this.f18145v0 = false;
        this.W.h();
        this.V.h();
        this.f18144u0 = false;
        um2 um2Var = this.Z;
        um2Var.getClass();
        um2Var.f17332a = i80.f12407a;
        um2Var.f17334c = 0;
        um2Var.f17333b = 2;
    }

    public final void l0() {
        try {
            rn2 rn2Var = this.zzw;
            rn2Var.getClass();
            rn2Var.zzk();
        } finally {
            P();
        }
    }

    public final boolean m0(int i10) throws zziw {
        di2 di2Var = this.f15395c;
        di2Var.zza = null;
        di2Var.zzb = null;
        fe2 fe2Var = this.T;
        fe2Var.h();
        int iP = p(di2Var, fe2Var, i10 | 4);
        if (iP == -5) {
            zzam(di2Var);
            return true;
        }
        if (iP != -4 || !fe2Var.g(4)) {
            return false;
        }
        this.E0 = true;
        p0();
        return false;
    }

    public final boolean n0() {
        if (this.A0) {
            this.f18148y0 = 1;
            this.z0 = 2;
        } else {
            ym2 ym2Var = this.zzq;
            ym2Var.getClass();
            this.zzp = ym2Var;
            this.f18148y0 = 0;
            this.z0 = 0;
        }
        return true;
    }

    public final void o0() throws zziw {
        if (this.A0) {
            this.f18148y0 = 1;
            this.z0 = 3;
        } else {
            L();
            I();
        }
    }

    public final void p0() throws zziw {
        int i10 = this.z0;
        if (i10 == 1) {
            l0();
            return;
        }
        if (i10 != 2) {
            if (i10 != 3) {
                this.F0 = true;
                i0();
                return;
            } else {
                L();
                I();
                return;
            }
        }
        l0();
        ym2 ym2Var = this.zzq;
        ym2Var.getClass();
        this.zzp = ym2Var;
        this.f18148y0 = 0;
        this.z0 = 0;
    }

    public final void q0(vn2 vn2Var) {
        this.I0 = vn2Var;
        if (vn2Var.f17722c != -9223372036854775807L) {
            this.K0 = true;
        }
    }

    public final vn2 r0() {
        ArrayDeque arrayDeque = this.Y;
        return !arrayDeque.isEmpty() ? (vn2) arrayDeque.getLast() : this.I0;
    }

    public final boolean s0(long j10, long j11) {
        if (j11 >= j10) {
            return false;
        }
        zn2 zn2Var = this.f18125b0;
        if (zn2Var == null || !Objects.equals(zn2Var.zzo, MimeTypes.AUDIO_OPUS)) {
            return true;
        }
        return j10 - j11 > 80000;
    }

    @Override // com.google.android.gms.internal.ads.pf2
    public final int u(zn2 zn2Var) throws zziw {
        try {
            return Y(this.R, zn2Var);
        } catch (zzuy e10) {
            throw zzN(e10, zn2Var, false, PlaybackException.ERROR_CODE_DECODER_QUERY_FAILED);
        }
    }

    @Nullable
    public final rn2 zzaE() {
        return this.zzw;
    }

    @Nullable
    public final zn2 zzaF() {
        return this.zzx;
    }

    @Nullable
    public final MediaFormat zzaG() {
        return this.zzy;
    }

    @Nullable
    public final tn2 zzaH() {
        return this.zzD;
    }

    public zzum zzaP(Throwable th, @Nullable tn2 tn2Var) {
        return new zzum(th, tn2Var);
    }

    @Nullable
    public final dj2 zzaY() {
        return this.f18126c0;
    }

    public abstract on2 zzaf(tn2 tn2Var, zn2 zn2Var, @Nullable MediaCrypto mediaCrypto, float f10);

    @Nullable
    @CallSuper
    public vg2 zzam(di2 di2Var) throws zziw {
        zn2 zn2Var;
        int i10;
        boolean z10 = true;
        this.G0 = true;
        zn2 zn2Var2 = di2Var.zzb;
        zn2Var2.getClass();
        String str = zn2Var2.zzo;
        if (str == null) {
            throw zzN(new IllegalArgumentException("Sample MIME type is null."), zn2Var2, false, PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
        }
        if ((str.equals(MimeTypes.VIDEO_AV1) || str.equals(MimeTypes.VIDEO_VP9)) && !zn2Var2.f19336i.isEmpty()) {
            sm2 sm2VarA = zn2Var2.a();
            sm2VarA.zzp(null);
            zn2Var = new zn2(sm2VarA);
        } else {
            zn2Var = zn2Var2;
        }
        this.zzq = di2Var.zza;
        this.zzn = zn2Var;
        if (this.f18143t0) {
            this.f18145v0 = true;
            return null;
        }
        rn2 rn2Var = this.zzw;
        if (rn2Var == null) {
            this.zzB = null;
            I();
            return null;
        }
        tn2 tn2Var = this.zzD;
        tn2Var.getClass();
        zn2 zn2Var3 = this.zzx;
        zn2Var3.getClass();
        ym2 ym2Var = this.zzp;
        ym2 ym2Var2 = this.zzq;
        if (ym2Var != ym2Var2) {
            o0();
            return new vg2(tn2Var.f16954a, zn2Var3, zn2Var, 0, 128);
        }
        vg2 vg2VarB0 = b0(tn2Var, zn2Var3, zn2Var);
        int i11 = vg2VarB0.f17631d;
        if (i11 != 0) {
            if (i11 == 1) {
                if (zzbj(zn2Var)) {
                    this.zzx = zn2Var;
                    if (ym2Var2 != ym2Var) {
                        n0();
                    } else if (this.A0) {
                        this.f18148y0 = 1;
                        this.z0 = 1;
                    }
                }
                i10 = 16;
            } else if (i11 != 2) {
                if (zzbj(zn2Var)) {
                    this.zzx = zn2Var;
                    if (ym2Var2 != ym2Var) {
                        n0();
                    }
                }
                i10 = 16;
            } else {
                if (zzbj(zn2Var)) {
                    this.f18146w0 = true;
                    this.f18147x0 = 1;
                    int i12 = this.f18132i0;
                    if (i12 != 2 && (i12 != 1 || zn2Var.f19339l != zn2Var3.f19339l || zn2Var.f19340m != zn2Var3.f19340m)) {
                        z10 = false;
                    }
                    this.f18134k0 = z10;
                    this.zzx = zn2Var;
                    if (ym2Var2 != ym2Var) {
                        n0();
                    }
                }
                i10 = 16;
            }
            return (i11 != 0 || (this.zzw == rn2Var && this.z0 != 3)) ? vg2VarB0 : new vg2(tn2Var.f16954a, zn2Var3, zn2Var, 0, i10);
        }
        o0();
        i10 = 0;
        if (i11 != 0) {
        }
    }

    public void zzan(zn2 zn2Var, @Nullable MediaFormat mediaFormat) throws zziw {
        throw null;
    }

    public abstract boolean zzaq(long j10, long j11, @Nullable rn2 rn2Var, @Nullable ByteBuffer byteBuffer, int i10, int i11, int i12, long j12, boolean z10, boolean z11, zn2 zn2Var) throws zziw;

    @Override // com.google.android.gms.internal.ads.pf2, com.google.android.gms.internal.ads.ej2, com.google.android.gms.internal.ads.zi2
    public void zzx(int i10, @Nullable Object obj) throws zziw {
        if (i10 == 11) {
            dj2 dj2Var = (dj2) obj;
            dj2Var.getClass();
            this.f18126c0 = dj2Var;
        }
    }
}
