package I0;

import B0.AbstractC0020g;
import B0.C0021h;
import B0.C0022i;
import B0.C0030q;
import B0.L;
import D0.I;
import L0.C;
import L0.c0;
import T0.AbstractC0302b;
import android.media.MediaCodec;
import android.media.MediaCrypto;
import android.media.MediaCryptoException;
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 d3.R0;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import u0.AbstractC1569e;
import u0.C1578n;
import u0.C1579o;
import v0.InterfaceC1668g;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public abstract class t extends AbstractC0020g {

    /* JADX INFO: renamed from: R0, reason: collision with root package name */
    public static final byte[] f3251R0 = {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};

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

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

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

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

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

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

    /* JADX INFO: renamed from: G0, reason: collision with root package name */
    public long f3258G0;
    public final m H;

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

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public final l f3260I;

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

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public final float f3262J;

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

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public final A0.h f3264K;
    public boolean K0;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public final A0.h f3265L;

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

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public final A0.h f3267M;

    /* JADX INFO: renamed from: M0, reason: collision with root package name */
    public C0030q f3268M0;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public final i f3269N;

    /* JADX INFO: renamed from: N0, reason: collision with root package name */
    public C0021h f3270N0;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public final MediaCodec.BufferInfo f3271O;

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

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public final ArrayDeque f3273P;

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

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public final I f3275Q;

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

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

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

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public K4.c f3279T;

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public K4.c f3280U;

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    public L f3281V;

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public MediaCrypto f3282W;
    public final long X;

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

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

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public n f3285a0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public t(int i, m mVar, float f3) {
        super(i);
        l lVar = l.f3232r;
        this.H = mVar;
        this.f3260I = lVar;
        this.f3262J = f3;
        this.f3264K = new A0.h(0);
        this.f3265L = new A0.h(0);
        this.f3267M = new A0.h(2);
        i iVar = new i(2);
        iVar.f3227B = 32;
        this.f3269N = iVar;
        this.f3271O = new MediaCodec.BufferInfo();
        this.f3283Y = 1.0f;
        this.f3284Z = 1.0f;
        this.X = -9223372036854775807L;
        this.f3273P = new ArrayDeque();
        this.f3272O0 = s.f3246e;
        iVar.h(0);
        iVar.f18u.order(ByteOrder.nativeOrder());
        I i5 = new I();
        i5.f1511a = InterfaceC1668g.f18020a;
        i5.f1513c = 0;
        i5.f1512b = 2;
        this.f3275Q = i5;
        this.f3289e0 = -1.0f;
        this.f3293i0 = 0;
        this.f3252A0 = 0;
        this.f3301r0 = -1;
        this.f3302s0 = -1;
        this.q0 = -9223372036854775807L;
        this.f3258G0 = -9223372036854775807L;
        this.f3259H0 = -9223372036854775807L;
        this.f3274P0 = -9223372036854775807L;
        this.f3300p0 = -9223372036854775807L;
        this.f3253B0 = 0;
        this.f3254C0 = 0;
        this.f3270N0 = new C0021h();
    }

    /* JADX WARN: Removed duplicated region for block: B:115:0x0313  */
    /* JADX WARN: Removed duplicated region for block: B:119:0x031c  */
    /* JADX WARN: Removed duplicated region for block: B:121:0x032c  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0081  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean A(long j8, long j9) throws C0030q {
        i iVar;
        boolean z8;
        boolean z9;
        int length;
        int i;
        int i5;
        AbstractC1709a.j(!this.f3263J0);
        i iVar2 = this.f3269N;
        if (iVar2.m()) {
            ByteBuffer byteBuffer = iVar2.f18u;
            int i8 = this.f3302s0;
            int i9 = iVar2.f3226A;
            long j10 = iVar2.f20w;
            boolean zR = R(this.f751B, iVar2.f3228z);
            boolean zD = iVar2.d(4);
            C1579o c1579o = this.f3278S;
            c1579o.getClass();
            iVar = iVar2;
            z8 = false;
            if (!f0(j8, j9, null, byteBuffer, i8, 0, i9, j10, zR, zD, c1579o)) {
                return false;
            }
            b0(iVar.f3228z);
            iVar.e();
        } else {
            iVar = iVar2;
            z8 = false;
        }
        if (this.f3261I0) {
            this.f3263J0 = true;
            return z8;
        }
        boolean z10 = true;
        boolean z11 = this.f3307x0;
        A0.h hVar = this.f3267M;
        if (z11) {
            AbstractC1709a.j(iVar.l(hVar));
            z9 = z8;
            this.f3307x0 = z9;
        } else {
            z9 = z8;
        }
        if (!this.f3308y0) {
            AbstractC1709a.j(!this.f3261I0);
            R0 r02 = this.f758s;
            r02.H();
            hVar.e();
            while (true) {
                hVar.e();
                int iU = u(r02, hVar, 0);
                if (iU == -5) {
                    Y(r02);
                    break;
                }
                if (iU != -4) {
                    if (iU != -3) {
                        throw new IllegalStateException();
                    }
                    if (j()) {
                        this.f3259H0 = this.f3258G0;
                    }
                } else {
                    if (hVar.d(4)) {
                        this.f3261I0 = z10;
                        this.f3259H0 = this.f3258G0;
                        break;
                    }
                    this.f3258G0 = Math.max(this.f3258G0, hVar.f20w);
                    if (j() || this.f3265L.d(536870912)) {
                        this.f3259H0 = this.f3258G0;
                    }
                    byte[] bArr = null;
                    if (this.K0) {
                        C1579o c1579o2 = this.f3277R;
                        c1579o2.getClass();
                        this.f3278S = c1579o2;
                        if (Objects.equals(c1579o2.f17358n, "audio/opus") && !this.f3278S.f17361q.isEmpty()) {
                            byte[] bArr2 = (byte[]) this.f3278S.f17361q.get(0);
                            int i10 = (bArr2[10] & 255) | ((bArr2[11] & 255) << 8);
                            C1578n c1578nA = this.f3278S.a();
                            c1578nA.f17303F = i10;
                            this.f3278S = new C1579o(c1578nA);
                        }
                        Z(this.f3278S, null);
                        this.K0 = false;
                    }
                    hVar.j();
                    C1579o c1579o3 = this.f3278S;
                    if (c1579o3 != null && Objects.equals(c1579o3.f17358n, "audio/opus")) {
                        if (hVar.d(268435456)) {
                            hVar.f16s = this.f3278S;
                            P(hVar);
                        }
                        if (this.f751B - hVar.f20w <= 80000) {
                            List list = this.f3278S.f17361q;
                            I i11 = this.f3275Q;
                            i11.getClass();
                            hVar.f18u.getClass();
                            if (hVar.f18u.limit() - hVar.f18u.position() != 0) {
                                if (i11.f1512b == 2 && (list.size() == z10 || list.size() == 3)) {
                                    bArr = (byte[]) list.get(0);
                                }
                                ByteBuffer byteBuffer2 = hVar.f18u;
                                int iPosition = byteBuffer2.position();
                                int iLimit = byteBuffer2.limit();
                                int i12 = iLimit - iPosition;
                                int i13 = (i12 + 255) / 255;
                                int i14 = i13 + 27 + i12;
                                if (i11.f1512b == 2) {
                                    length = bArr != null ? bArr.length + 28 : 47;
                                    i14 = length + 44 + i14;
                                } else {
                                    length = 0;
                                }
                                if (i11.f1511a.capacity() < i14) {
                                    i11.f1511a = ByteBuffer.allocate(i14).order(ByteOrder.LITTLE_ENDIAN);
                                } else {
                                    i11.f1511a.clear();
                                }
                                ByteBuffer byteBuffer3 = i11.f1511a;
                                if (i11.f1512b == 2) {
                                    if (bArr != null) {
                                        I.a(byteBuffer3, 0L, 0, 1, true);
                                        i5 = iLimit;
                                        long length2 = bArr.length;
                                        if ((length2 >> 8) != 0) {
                                            throw new IllegalArgumentException(U2.a.G("out of range: %s", Long.valueOf(length2)));
                                        }
                                        byteBuffer3.put((byte) length2);
                                        byteBuffer3.put(bArr);
                                        i = length;
                                        byteBuffer3.putInt(22, x0.v.m(byteBuffer3.arrayOffset(), bArr.length + 28, 0, byteBuffer3.array()));
                                        byteBuffer3.position(bArr.length + 28);
                                    } else {
                                        i = length;
                                        i5 = iLimit;
                                        byteBuffer3.put(I.f1509d);
                                    }
                                    byteBuffer3.put(I.f1510e);
                                } else {
                                    i = length;
                                    i5 = iLimit;
                                }
                                int iJ = i11.f1513c + ((int) ((AbstractC0302b.j(byteBuffer2.get(0), byteBuffer2.limit() > 1 ? byteBuffer2.get(1) : (byte) 0) * 48000) / 1000000));
                                i11.f1513c = iJ;
                                I.a(byteBuffer3, iJ, i11.f1512b, i13, false);
                                for (int i15 = 0; i15 < i13; i15++) {
                                    if (i12 >= 255) {
                                        byteBuffer3.put((byte) -1);
                                        i12 -= 255;
                                    } else {
                                        byteBuffer3.put((byte) i12);
                                        i12 = 0;
                                    }
                                }
                                int i16 = i5;
                                while (iPosition < i16) {
                                    byteBuffer3.put(byteBuffer2.get(iPosition));
                                    iPosition++;
                                }
                                byteBuffer2.position(byteBuffer2.limit());
                                byteBuffer3.flip();
                                if (i11.f1512b == 2) {
                                    byteBuffer3.putInt(i + 66, x0.v.m(byteBuffer3.arrayOffset() + i + 44, byteBuffer3.limit() - byteBuffer3.position(), 0, byteBuffer3.array()));
                                } else {
                                    byteBuffer3.putInt(22, x0.v.m(byteBuffer3.arrayOffset(), byteBuffer3.limit() - byteBuffer3.position(), 0, byteBuffer3.array()));
                                }
                                i11.f1512b++;
                                i11.f1511a = byteBuffer3;
                                hVar.e();
                                hVar.h(i11.f1511a.remaining());
                                hVar.f18u.put(i11.f1511a);
                                hVar.j();
                            }
                            if (!iVar.m()) {
                            }
                        }
                    } else if (!iVar.m()) {
                        long j11 = this.f751B;
                        if (R(j11, iVar.f3228z) != R(j11, hVar.f20w)) {
                            break;
                        }
                    } else {
                        if (!iVar.l(hVar)) {
                            break;
                        }
                        z10 = true;
                    }
                }
            }
            this.f3307x0 = true;
            if (iVar.m()) {
                iVar.j();
            }
            if (iVar.m() || this.f3261I0 || this.f3308y0) {
                return true;
            }
        } else {
            if (iVar.m()) {
                return true;
            }
            D();
            this.f3308y0 = z9;
            S();
            if (this.f3306w0) {
            }
        }
        return false;
    }

    public abstract C0022i B(q qVar, C1579o c1579o, C1579o c1579o2);

    public p C(IllegalStateException illegalStateException, q qVar) {
        return new p(illegalStateException, qVar);
    }

    public final void D() {
        this.f3308y0 = false;
        this.f3269N.e();
        this.f3267M.e();
        this.f3307x0 = false;
        this.f3306w0 = false;
        I i = this.f3275Q;
        i.getClass();
        i.f1511a = InterfaceC1668g.f18020a;
        i.f1513c = 0;
        i.f1512b = 2;
    }

    public final boolean E() throws C0030q {
        if (!this.f3255D0) {
            s0();
            return true;
        }
        this.f3253B0 = 1;
        if (this.f3295k0) {
            this.f3254C0 = 3;
            return false;
        }
        this.f3254C0 = 2;
        return true;
    }

    public final boolean F(long j8, long j9) throws C0030q {
        boolean z8;
        boolean z9;
        MediaCodec.BufferInfo bufferInfo;
        boolean zF0;
        ByteBuffer byteBuffer;
        int i;
        int i5;
        long j10;
        boolean z10;
        boolean z11;
        C1579o c1579o;
        int iG;
        n nVar = this.f3285a0;
        nVar.getClass();
        boolean z12 = this.f3302s0 >= 0;
        MediaCodec.BufferInfo bufferInfo2 = this.f3271O;
        if (!z12) {
            if (this.f3296l0 && this.f3256E0) {
                try {
                    iG = nVar.g(bufferInfo2);
                } catch (IllegalStateException unused) {
                    e0();
                    if (this.f3263J0) {
                        h0();
                    }
                }
            } else {
                iG = nVar.g(bufferInfo2);
            }
            if (iG < 0) {
                if (iG == -2) {
                    this.f3257F0 = true;
                    n nVar2 = this.f3285a0;
                    nVar2.getClass();
                    MediaFormat mediaFormatC = nVar2.C();
                    if (this.f3293i0 != 0 && mediaFormatC.getInteger("width") == 32 && mediaFormatC.getInteger("height") == 32) {
                        this.f3298n0 = true;
                        return true;
                    }
                    this.f3287c0 = mediaFormatC;
                    this.f3288d0 = true;
                    return true;
                }
                if (this.f3299o0 && (this.f3261I0 || this.f3253B0 == 2)) {
                    e0();
                }
                long j11 = this.f3300p0;
                if (j11 != -9223372036854775807L) {
                    long j12 = j11 + 100;
                    this.f762w.getClass();
                    if (j12 < System.currentTimeMillis()) {
                        e0();
                        return false;
                    }
                }
                return false;
            }
            if (this.f3298n0) {
                this.f3298n0 = false;
                nVar.n(iG);
                return true;
            }
            if (bufferInfo2.size == 0 && (bufferInfo2.flags & 4) != 0) {
                e0();
                return false;
            }
            this.f3302s0 = iG;
            ByteBuffer byteBufferQ = nVar.q(iG);
            this.f3303t0 = byteBufferQ;
            if (byteBufferQ != null) {
                byteBufferQ.position(bufferInfo2.offset);
                this.f3303t0.limit(bufferInfo2.offset + bufferInfo2.size);
            }
            long j13 = bufferInfo2.presentationTimeUs;
            this.f3304u0 = j13 < this.f751B;
            long j14 = this.f3259H0;
            this.f3305v0 = j14 != -9223372036854775807L && j14 <= j13;
            t0(j13);
        }
        if (this.f3296l0 && this.f3256E0) {
            try {
                byteBuffer = this.f3303t0;
                i = this.f3302s0;
                i5 = bufferInfo2.flags;
                j10 = bufferInfo2.presentationTimeUs;
                z10 = this.f3304u0;
                z11 = this.f3305v0;
                c1579o = this.f3278S;
                c1579o.getClass();
                z8 = true;
                z9 = false;
                bufferInfo = bufferInfo2;
            } catch (IllegalStateException unused2) {
                z9 = false;
            }
            try {
                zF0 = f0(j8, j9, nVar, byteBuffer, i, i5, 1, j10, z10, z11, c1579o);
            } catch (IllegalStateException unused3) {
                e0();
                if (!this.f3263J0) {
                    return z9;
                }
                h0();
                return z9;
            }
        } else {
            z8 = true;
            z9 = false;
            bufferInfo = bufferInfo2;
            ByteBuffer byteBuffer2 = this.f3303t0;
            int i8 = this.f3302s0;
            int i9 = bufferInfo.flags;
            long j15 = bufferInfo.presentationTimeUs;
            boolean z13 = this.f3304u0;
            boolean z14 = this.f3305v0;
            C1579o c1579o2 = this.f3278S;
            c1579o2.getClass();
            zF0 = f0(j8, j9, nVar, byteBuffer2, i8, i9, 1, j15, z13, z14, c1579o2);
        }
        if (!zF0) {
            return z9;
        }
        b0(bufferInfo.presentationTimeUs);
        boolean z15 = (bufferInfo.flags & 4) != 0 ? z8 : z9;
        if (!z15 && this.f3256E0 && this.f3305v0) {
            this.f762w.getClass();
            this.f3300p0 = System.currentTimeMillis();
        }
        this.f3302s0 = -1;
        this.f3303t0 = null;
        if (!z15) {
            return z8;
        }
        e0();
        return z9;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0030  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean G() throws C0030q {
        n nVar = this.f3285a0;
        if (nVar != null && this.f3253B0 != 2 && !this.f3261I0) {
            int i = this.f3301r0;
            A0.h hVar = this.f3265L;
            if (i < 0) {
                int iY = nVar.y();
                this.f3301r0 = iY;
                if (iY >= 0) {
                    hVar.f18u = nVar.l(iY);
                    hVar.e();
                    if (this.f3253B0 != 1) {
                        if (!this.f3299o0) {
                            this.f3256E0 = true;
                            nVar.f(this.f3301r0, 0, 0L, 4);
                            this.f3301r0 = -1;
                            hVar.f18u = null;
                        }
                        this.f3253B0 = 2;
                        return false;
                    }
                    if (this.f3297m0) {
                        this.f3297m0 = false;
                        ByteBuffer byteBuffer = hVar.f18u;
                        byteBuffer.getClass();
                        byteBuffer.put(f3251R0);
                        nVar.f(this.f3301r0, 38, 0L, 0);
                        this.f3301r0 = -1;
                        hVar.f18u = null;
                        this.f3255D0 = true;
                        return true;
                    }
                    if (this.f3252A0 == 1) {
                        int i5 = 0;
                        while (true) {
                            C1579o c1579o = this.f3286b0;
                            c1579o.getClass();
                            if (i5 >= c1579o.f17361q.size()) {
                                break;
                            }
                            byte[] bArr = (byte[]) this.f3286b0.f17361q.get(i5);
                            ByteBuffer byteBuffer2 = hVar.f18u;
                            byteBuffer2.getClass();
                            byteBuffer2.put(bArr);
                            i5++;
                        }
                        this.f3252A0 = 2;
                    }
                    ByteBuffer byteBuffer3 = hVar.f18u;
                    byteBuffer3.getClass();
                    int iPosition = byteBuffer3.position();
                    R0 r02 = this.f758s;
                    r02.H();
                    try {
                        int iU = u(r02, hVar, 0);
                        if (iU == -3) {
                            if (j()) {
                                this.f3259H0 = this.f3258G0;
                                return false;
                            }
                        } else {
                            if (iU == -5) {
                                if (this.f3252A0 == 2) {
                                    hVar.e();
                                    this.f3252A0 = 1;
                                }
                                Y(r02);
                                return true;
                            }
                            if (!hVar.d(4)) {
                                if (!this.f3255D0 && !hVar.d(1)) {
                                    hVar.e();
                                    if (this.f3252A0 == 2) {
                                        this.f3252A0 = 1;
                                        return true;
                                    }
                                } else if (!n0(hVar)) {
                                    boolean zD = hVar.d(1073741824);
                                    if (zD) {
                                        A0.d dVar = hVar.f17t;
                                        if (iPosition == 0) {
                                            dVar.getClass();
                                        } else {
                                            if (dVar.f10d == null) {
                                                int[] iArr = new int[1];
                                                dVar.f10d = iArr;
                                                dVar.i.numBytesOfClearData = iArr;
                                            }
                                            int[] iArr2 = dVar.f10d;
                                            iArr2[0] = iArr2[0] + iPosition;
                                        }
                                    }
                                    long j8 = hVar.f20w;
                                    if (this.K0) {
                                        ArrayDeque arrayDeque = this.f3273P;
                                        if (arrayDeque.isEmpty()) {
                                            S0.f fVar = this.f3272O0.f3250d;
                                            C1579o c1579o2 = this.f3277R;
                                            c1579o2.getClass();
                                            fVar.a(j8, c1579o2);
                                        } else {
                                            S0.f fVar2 = ((s) arrayDeque.peekLast()).f3250d;
                                            C1579o c1579o3 = this.f3277R;
                                            c1579o3.getClass();
                                            fVar2.a(j8, c1579o3);
                                        }
                                        this.K0 = false;
                                    }
                                    this.f3258G0 = Math.max(this.f3258G0, j8);
                                    if (j() || hVar.d(536870912)) {
                                        this.f3259H0 = this.f3258G0;
                                    }
                                    hVar.j();
                                    if (hVar.d(268435456)) {
                                        P(hVar);
                                    }
                                    d0(hVar);
                                    int iK = K(hVar);
                                    if (zD) {
                                        nVar.d(this.f3301r0, hVar.f17t, j8, iK);
                                    } else {
                                        int i8 = this.f3301r0;
                                        ByteBuffer byteBuffer4 = hVar.f18u;
                                        byteBuffer4.getClass();
                                        nVar.f(i8, byteBuffer4.limit(), j8, iK);
                                    }
                                    this.f3301r0 = -1;
                                    hVar.f18u = null;
                                    this.f3255D0 = true;
                                    this.f3252A0 = 0;
                                    this.f3270N0.f771c++;
                                    return true;
                                }
                                return true;
                            }
                            this.f3259H0 = this.f3258G0;
                            if (this.f3252A0 == 2) {
                                hVar.e();
                                this.f3252A0 = 1;
                            }
                            this.f3261I0 = true;
                            if (!this.f3255D0) {
                                e0();
                                return false;
                            }
                            if (!this.f3299o0) {
                                this.f3256E0 = true;
                                nVar.f(this.f3301r0, 0, 0L, 4);
                                this.f3301r0 = -1;
                                hVar.f18u = null;
                                return false;
                            }
                        }
                    } catch (A0.g e8) {
                        V(e8);
                        g0(0);
                        H();
                        return true;
                    }
                }
            } else if (this.f3253B0 != 1) {
            }
        }
        return false;
    }

    public final void H() {
        try {
            n nVar = this.f3285a0;
            AbstractC1709a.k(nVar);
            nVar.flush();
        } finally {
            j0();
        }
    }

    public final boolean I() {
        if (this.f3285a0 == null) {
            return false;
        }
        int i = this.f3254C0;
        if (i == 3 || ((this.f3294j0 && !this.f3257F0) || (this.f3295k0 && this.f3256E0))) {
            h0();
            return true;
        }
        if (i == 2) {
            int i5 = x0.v.f18553a;
            AbstractC1709a.j(i5 >= 23);
            if (i5 >= 23) {
                try {
                    s0();
                } catch (C0030q e8) {
                    AbstractC1709a.C("MediaCodecRenderer", "Failed to update the DRM session, releasing the codec instead.", e8);
                    h0();
                    return true;
                }
            }
        }
        H();
        return false;
    }

    public final List J(boolean z8) {
        C1579o c1579o = this.f3277R;
        c1579o.getClass();
        l lVar = this.f3260I;
        ArrayList arrayListN = N(lVar, c1579o, z8);
        if (!arrayListN.isEmpty() || !z8) {
            return arrayListN;
        }
        ArrayList arrayListN2 = N(lVar, c1579o, false);
        if (!arrayListN2.isEmpty()) {
            AbstractC1709a.B("MediaCodecRenderer", "Drm session requires secure decoder for " + c1579o.f17358n + ", but no secure decoder available. Trying to proceed with " + arrayListN2 + ".");
        }
        return arrayListN2;
    }

    public int K(A0.h hVar) {
        return 0;
    }

    public boolean L() {
        return false;
    }

    public abstract float M(float f3, C1579o[] c1579oArr);

    public abstract ArrayList N(l lVar, C1579o c1579o, boolean z8);

    public abstract O3.q O(q qVar, C1579o c1579o, MediaCrypto mediaCrypto, float f3);

    public abstract void P(A0.h hVar);

    /* JADX WARN: Removed duplicated region for block: B:32:0x00ea  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x0122  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void Q(q qVar, MediaCrypto mediaCrypto) {
        float fM;
        int i;
        C1579o c1579o = this.f3277R;
        c1579o.getClass();
        String str = qVar.f3234a;
        int i5 = x0.v.f18553a;
        if (i5 < 23) {
            fM = -1.0f;
        } else {
            float f3 = this.f3284Z;
            C1579o[] c1579oArr = this.f765z;
            c1579oArr.getClass();
            fM = M(f3, c1579oArr);
        }
        float f7 = fM > this.f3262J ? fM : -1.0f;
        this.f762w.getClass();
        long jElapsedRealtime = SystemClock.elapsedRealtime();
        O3.q qVarO = O(qVar, c1579o, mediaCrypto, f7);
        if (i5 >= 31) {
            C0.l lVar = this.f761v;
            lVar.getClass();
            LogSessionId logSessionIdA = lVar.a();
            LogSessionId unused = LogSessionId.LOG_SESSION_ID_NONE;
            if (!logSessionIdA.equals(LogSessionId.LOG_SESSION_ID_NONE)) {
                ((MediaFormat) qVarO.f5166b).setString("log-session-id", logSessionIdA.getStringId());
            }
        }
        try {
            Trace.beginSection("createCodec:" + str);
            n nVarD = this.H.D(qVarO);
            this.f3285a0 = nVarD;
            nVarD.t(new K4.c(17, this));
            Trace.endSection();
            this.f762w.getClass();
            float f8 = f7;
            long jElapsedRealtime2 = SystemClock.elapsedRealtime();
            if (!qVar.e(c1579o)) {
                String strC = C1579o.c(c1579o);
                Locale locale = Locale.US;
                AbstractC1709a.B("MediaCodecRenderer", "Format exceeds selected codec's capabilities [" + strC + ", " + str + "]");
            }
            this.f3292h0 = qVar;
            this.f3289e0 = f8;
            this.f3286b0 = c1579o;
            if (i5 <= 25 && "OMX.Exynos.avc.dec.secure".equals(str)) {
                String str2 = Build.MODEL;
                if (str2.startsWith("SM-T585") || str2.startsWith("SM-A510") || str2.startsWith("SM-A520") || str2.startsWith("SM-J700")) {
                    i = 2;
                }
            } else if (i5 >= 24 || !("OMX.Nvidia.h264.decode".equals(str) || "OMX.Nvidia.h264.decode.secure".equals(str))) {
                i = 0;
            } else {
                String str3 = Build.DEVICE;
                if ("flounder".equals(str3) || "flounder_lte".equals(str3) || "grouper".equals(str3) || "tilapia".equals(str3)) {
                    i = 1;
                }
            }
            this.f3293i0 = i;
            this.f3294j0 = i5 == 29 && "c2.android.aac.decoder".equals(str);
            this.f3295k0 = i5 <= 23 && "OMX.google.vorbis.decoder".equals(str);
            this.f3296l0 = i5 == 21 && "OMX.google.aac.decoder".equals(str);
            String str4 = qVar.f3234a;
            this.f3299o0 = (i5 <= 25 && "OMX.rk.video_decoder.avc".equals(str4)) || (i5 <= 29 && ("OMX.broadcom.video_decoder.tunnel".equals(str4) || "OMX.broadcom.video_decoder.tunnel.secure".equals(str4) || "OMX.bcm.vdec.avc.tunnel".equals(str4) || "OMX.bcm.vdec.avc.tunnel.secure".equals(str4) || "OMX.bcm.vdec.hevc.tunnel".equals(str4) || "OMX.bcm.vdec.hevc.tunnel.secure".equals(str4))) || (("Amazon".equals(Build.MANUFACTURER) && "AFTS".equals(Build.MODEL) && qVar.f3239f) || L());
            this.f3285a0.getClass();
            if (this.f763x == 2) {
                this.f762w.getClass();
                this.q0 = SystemClock.elapsedRealtime() + 1000;
            }
            this.f3270N0.f769a++;
            W(jElapsedRealtime2, str, jElapsedRealtime2 - jElapsedRealtime);
        } catch (Throwable th) {
            Trace.endSection();
            throw th;
        }
    }

    public final boolean R(long j8, long j9) {
        if (j9 >= j8) {
            return false;
        }
        C1579o c1579o = this.f3278S;
        return c1579o == null || !Objects.equals(c1579o.f17358n, "audio/opus") || j8 - j9 > 80000;
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x0089  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00ce  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void S() throws C0030q {
        C1579o c1579o;
        K4.c cVar;
        if (this.f3285a0 != null || this.f3306w0 || (c1579o = this.f3277R) == null) {
            return;
        }
        boolean z8 = true;
        boolean z9 = this.f3280U == null && p0(c1579o);
        String str = c1579o.f17358n;
        if (z9) {
            D();
            boolean zEquals = "audio/mp4a-latm".equals(str);
            i iVar = this.f3269N;
            if (zEquals || "audio/mpeg".equals(str) || "audio/opus".equals(str)) {
                iVar.getClass();
                iVar.f3227B = 32;
            } else {
                iVar.getClass();
                iVar.f3227B = 1;
            }
            this.f3306w0 = true;
            return;
        }
        l0(this.f3280U);
        if (this.f3279T == null) {
            try {
                cVar = this.f3279T;
                if (cVar == null && (cVar.A() == 3 || this.f3279T.A() == 4)) {
                    K4.c cVar2 = this.f3279T;
                    AbstractC1709a.k(str);
                    if (cVar2.K(str)) {
                    }
                    T(this.f3282W, z8);
                } else {
                    z8 = false;
                    T(this.f3282W, z8);
                }
            } catch (r e8) {
                throw f(e8, c1579o, false, 4001);
            }
        } else {
            AbstractC1709a.j(this.f3282W == null);
            K4.c cVar3 = this.f3279T;
            A0.b bVarW = cVar3.w();
            if (E0.i.f1976a && (bVarW instanceof E0.i)) {
                int iA = cVar3.A();
                if (iA == 1) {
                    E0.c cVarX = cVar3.x();
                    cVarX.getClass();
                    throw f(cVarX, this.f3277R, false, cVarX.f1969q);
                }
                if (iA == 4) {
                }
            } else {
                if (bVarW == null) {
                    if (cVar3.x() != null) {
                    }
                } else if (bVarW instanceof E0.i) {
                    try {
                        this.f3282W = new MediaCrypto(null, null);
                    } catch (MediaCryptoException e9) {
                        throw f(e9, this.f3277R, false, 6006);
                    }
                }
                cVar = this.f3279T;
                if (cVar == null) {
                    z8 = false;
                    T(this.f3282W, z8);
                }
            }
        }
        MediaCrypto mediaCrypto = this.f3282W;
        if (mediaCrypto == null || this.f3285a0 != null) {
            return;
        }
        mediaCrypto.release();
        this.f3282W = null;
    }

    public final void T(MediaCrypto mediaCrypto, boolean z8) throws r {
        C1579o c1579o = this.f3277R;
        c1579o.getClass();
        if (this.f3290f0 == null) {
            try {
                List listJ = J(z8);
                this.f3290f0 = new ArrayDeque();
                ArrayList arrayList = (ArrayList) listJ;
                if (!arrayList.isEmpty()) {
                    this.f3290f0.add((q) arrayList.get(0));
                }
                this.f3291g0 = null;
            } catch (w e8) {
                throw new r(c1579o, e8, z8, -49998);
            }
        }
        if (this.f3290f0.isEmpty()) {
            throw new r(c1579o, null, z8, -49999);
        }
        ArrayDeque arrayDeque = this.f3290f0;
        arrayDeque.getClass();
        while (this.f3285a0 == null) {
            q qVar = (q) arrayDeque.peekFirst();
            qVar.getClass();
            if (!U(c1579o) || !o0(qVar)) {
                return;
            }
            try {
                Q(qVar, mediaCrypto);
            } catch (Exception e9) {
                AbstractC1709a.C("MediaCodecRenderer", "Failed to initialize decoder: " + qVar, e9);
                arrayDeque.removeFirst();
                r rVar = new r("Decoder init failed: " + qVar.f3234a + ", " + c1579o, e9, c1579o.f17358n, z8, qVar, e9 instanceof MediaCodec.CodecException ? ((MediaCodec.CodecException) e9).getDiagnosticInfo() : null);
                V(rVar);
                r rVar2 = this.f3291g0;
                if (rVar2 == null) {
                    this.f3291g0 = rVar;
                } else {
                    this.f3291g0 = new r(rVar2.getMessage(), rVar2.getCause(), rVar2.f3242q, rVar2.f3243r, rVar2.f3244s, rVar2.f3245t);
                }
                if (arrayDeque.isEmpty()) {
                    throw this.f3291g0;
                }
            }
        }
        this.f3290f0 = null;
    }

    public boolean U(C1579o c1579o) {
        return true;
    }

    public abstract void V(Exception exc);

    public abstract void W(long j8, String str, long j9);

    public abstract void X(String str);

    /* JADX WARN: Code restructure failed: missing block: B:62:0x00e3, code lost:
    
        if (r4.K(r3) != false) goto L134;
     */
    /* JADX WARN: Removed duplicated region for block: B:87:0x011f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0022i Y(R0 r02) {
        C1579o c1579o;
        int i;
        A0.b bVarW;
        A0.b bVarW2;
        boolean z8 = true;
        this.K0 = true;
        C1579o c1579o2 = (C1579o) r02.f11693s;
        c1579o2.getClass();
        String str = c1579o2.f17358n;
        if (str == null) {
            throw f(new IllegalArgumentException("Sample MIME type is null."), c1579o2, false, 4005);
        }
        if (!str.equals("video/av01") || c1579o2.f17361q.isEmpty()) {
            c1579o = c1579o2;
        } else {
            C1578n c1578nA = c1579o2.a();
            c1578nA.f17323p = null;
            c1579o = new C1579o(c1578nA);
        }
        K4.c cVar = (K4.c) r02.f11692r;
        K4.c cVar2 = this.f3280U;
        if (cVar2 != cVar) {
            if (cVar != null) {
                cVar.q(null);
            }
            if (cVar2 != null) {
                cVar2.J(null);
            }
        }
        this.f3280U = cVar;
        this.f3277R = c1579o;
        if (this.f3306w0) {
            this.f3308y0 = true;
            return null;
        }
        n nVar = this.f3285a0;
        if (nVar == null) {
            this.f3290f0 = null;
            S();
            return null;
        }
        q qVar = this.f3292h0;
        qVar.getClass();
        C1579o c1579o3 = this.f3286b0;
        c1579o3.getClass();
        K4.c cVar3 = this.f3279T;
        K4.c cVar4 = this.f3280U;
        if (cVar3 != cVar4) {
            if (cVar4 != null && cVar3 != null && (bVarW = cVar4.w()) != null && (bVarW2 = cVar3.w()) != null && bVarW.getClass().equals(bVarW2.getClass())) {
                if (bVarW instanceof E0.i) {
                    if (cVar4.z().equals(cVar3.z()) && x0.v.f18553a >= 23) {
                        UUID uuid = AbstractC1569e.f17276e;
                        if (!uuid.equals(cVar3.z()) && !uuid.equals(cVar4.z())) {
                            if (!qVar.f3239f) {
                                if (cVar4.A() != 2) {
                                    if (cVar4.A() == 3 || cVar4.A() == 4) {
                                        String str2 = c1579o.f17358n;
                                        str2.getClass();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (this.f3255D0) {
                this.f3253B0 = 1;
                this.f3254C0 = 3;
            } else {
                h0();
                S();
            }
            return new C0022i(qVar.f3234a, c1579o3, c1579o, 0, 128);
        }
        boolean z9 = this.f3280U != this.f3279T;
        AbstractC1709a.j(!z9 || x0.v.f18553a >= 23);
        C0022i c0022iB = B(qVar, c1579o3, c1579o);
        int i5 = c0022iB.f788d;
        if (i5 != 0) {
            i = 16;
            if (i5 != 1) {
                if (i5 != 2) {
                    if (i5 != 3) {
                        throw new IllegalStateException();
                    }
                    if (r0(c1579o)) {
                        this.f3286b0 = c1579o;
                        if (z9 && !E()) {
                            i = 2;
                        }
                    }
                } else if (r0(c1579o)) {
                    this.f3309z0 = true;
                    this.f3252A0 = 1;
                    int i8 = this.f3293i0;
                    if (i8 != 2 && (i8 != 1 || c1579o.f17365u != c1579o3.f17365u || c1579o.f17366v != c1579o3.f17366v)) {
                        z8 = false;
                    }
                    this.f3297m0 = z8;
                    this.f3286b0 = c1579o;
                    if (!z9 || E()) {
                    }
                }
            } else if (r0(c1579o)) {
                this.f3286b0 = c1579o;
                if (z9) {
                    if (!E()) {
                    }
                } else if (this.f3255D0) {
                    this.f3253B0 = 1;
                    if (this.f3295k0) {
                        this.f3254C0 = 3;
                        i = 2;
                    } else {
                        this.f3254C0 = 1;
                    }
                }
            }
            return (i5 != 0 || (this.f3285a0 == nVar && this.f3254C0 != 3)) ? c0022iB : new C0022i(qVar.f3234a, c1579o3, c1579o, 0, i);
        }
        if (this.f3255D0) {
            this.f3253B0 = 1;
            this.f3254C0 = 3;
        } else {
            h0();
            S();
        }
        i = 0;
        if (i5 != 0) {
        }
    }

    public abstract void Z(C1579o c1579o, MediaFormat mediaFormat);

    public void b0(long j8) {
        this.f3274P0 = j8;
        while (true) {
            ArrayDeque arrayDeque = this.f3273P;
            if (arrayDeque.isEmpty() || j8 < ((s) arrayDeque.peek()).f3247a) {
                return;
            }
            s sVar = (s) arrayDeque.poll();
            sVar.getClass();
            m0(sVar);
            c0();
        }
    }

    public abstract void c0();

    public final void e0() throws C0030q {
        int i = this.f3254C0;
        if (i == 1) {
            H();
            return;
        }
        if (i == 2) {
            H();
            s0();
        } else if (i != 3) {
            this.f3263J0 = true;
            i0();
        } else {
            h0();
            S();
        }
    }

    public abstract boolean f0(long j8, long j9, n nVar, ByteBuffer byteBuffer, int i, int i5, int i8, long j10, boolean z8, boolean z9, C1579o c1579o);

    public final boolean g0(int i) throws C0030q {
        R0 r02 = this.f758s;
        r02.H();
        A0.h hVar = this.f3264K;
        hVar.e();
        int iU = u(r02, hVar, i | 4);
        if (iU == -5) {
            Y(r02);
            return true;
        }
        if (iU != -4 || !hVar.d(4)) {
            return false;
        }
        this.f3261I0 = true;
        e0();
        return false;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void h0() {
        try {
            n nVar = this.f3285a0;
            if (nVar != null) {
                nVar.a();
                this.f3270N0.f770b++;
                q qVar = this.f3292h0;
                qVar.getClass();
                X(qVar.f3234a);
            }
            this.f3285a0 = null;
            try {
                MediaCrypto mediaCrypto = this.f3282W;
                if (mediaCrypto != null) {
                    mediaCrypto.release();
                }
            } finally {
            }
        } catch (Throwable th) {
            this.f3285a0 = null;
            try {
                MediaCrypto mediaCrypto2 = this.f3282W;
                if (mediaCrypto2 != null) {
                    mediaCrypto2.release();
                }
                throw th;
            } finally {
            }
        }
    }

    public abstract void i0();

    public void j0() {
        this.f3301r0 = -1;
        this.f3265L.f18u = null;
        this.f3302s0 = -1;
        this.f3303t0 = null;
        this.q0 = -9223372036854775807L;
        this.f3256E0 = false;
        this.f3300p0 = -9223372036854775807L;
        this.f3255D0 = false;
        this.f3297m0 = false;
        this.f3298n0 = false;
        this.f3304u0 = false;
        this.f3305v0 = false;
        this.f3258G0 = -9223372036854775807L;
        this.f3259H0 = -9223372036854775807L;
        this.f3274P0 = -9223372036854775807L;
        this.f3253B0 = 0;
        this.f3254C0 = 0;
        this.f3252A0 = this.f3309z0 ? 1 : 0;
    }

    public final void k0() {
        j0();
        this.f3268M0 = null;
        this.f3290f0 = null;
        this.f3292h0 = null;
        this.f3286b0 = null;
        this.f3287c0 = null;
        this.f3288d0 = false;
        this.f3257F0 = false;
        this.f3289e0 = -1.0f;
        this.f3293i0 = 0;
        this.f3294j0 = false;
        this.f3295k0 = false;
        this.f3296l0 = false;
        this.f3299o0 = false;
        this.f3309z0 = false;
        this.f3252A0 = 0;
    }

    @Override // B0.AbstractC0020g
    public boolean l() {
        boolean zF;
        if (this.f3277R != null) {
            if (j()) {
                zF = this.D;
            } else {
                c0 c0Var = this.f764y;
                c0Var.getClass();
                zF = c0Var.f();
            }
            if (!zF) {
                if (!(this.f3302s0 >= 0)) {
                    if (this.q0 != -9223372036854775807L) {
                        this.f762w.getClass();
                        if (SystemClock.elapsedRealtime() < this.q0) {
                        }
                    }
                }
            }
            return true;
        }
        return false;
    }

    public final void l0(K4.c cVar) {
        K4.c cVar2 = this.f3279T;
        if (cVar2 != cVar) {
            if (cVar != null) {
                cVar.q(null);
            }
            if (cVar2 != null) {
                cVar2.J(null);
            }
        }
        this.f3279T = cVar;
    }

    @Override // B0.AbstractC0020g
    public void m() {
        this.f3277R = null;
        m0(s.f3246e);
        this.f3273P.clear();
        I();
    }

    public final void m0(s sVar) {
        this.f3272O0 = sVar;
        if (sVar.f3249c != -9223372036854775807L) {
            this.f3276Q0 = true;
            a0();
        }
    }

    public boolean n0(A0.h hVar) {
        return false;
    }

    @Override // B0.AbstractC0020g
    public void o(long j8, boolean z8) {
        this.f3261I0 = false;
        this.f3263J0 = false;
        this.f3266L0 = false;
        if (this.f3306w0) {
            this.f3269N.e();
            this.f3267M.e();
            this.f3307x0 = false;
            I i = this.f3275Q;
            i.getClass();
            i.f1511a = InterfaceC1668g.f18020a;
            i.f1513c = 0;
            i.f1512b = 2;
        } else if (I()) {
            S();
        }
        if (this.f3272O0.f3250d.h() > 0) {
            this.K0 = true;
        }
        this.f3272O0.f3250d.b();
        this.f3273P.clear();
    }

    public boolean o0(q qVar) {
        return true;
    }

    public boolean p0(C1579o c1579o) {
        return false;
    }

    public abstract int q0(l lVar, C1579o c1579o);

    public final boolean r0(C1579o c1579o) throws C0030q {
        if (x0.v.f18553a >= 23 && this.f3285a0 != null && this.f3254C0 != 3 && this.f763x != 0) {
            float f3 = this.f3284Z;
            c1579o.getClass();
            C1579o[] c1579oArr = this.f765z;
            c1579oArr.getClass();
            float fM = M(f3, c1579oArr);
            float f7 = this.f3289e0;
            if (f7 != fM) {
                if (fM == -1.0f) {
                    if (this.f3255D0) {
                        this.f3253B0 = 1;
                        this.f3254C0 = 3;
                        return false;
                    }
                    h0();
                    S();
                    return false;
                }
                if (f7 != -1.0f || fM > this.f3262J) {
                    Bundle bundle = new Bundle();
                    bundle.putFloat("operating-rate", fM);
                    n nVar = this.f3285a0;
                    nVar.getClass();
                    nVar.c(bundle);
                    this.f3289e0 = fM;
                }
            }
        }
        return true;
    }

    public final void s0() throws C0030q {
        K4.c cVar = this.f3280U;
        cVar.getClass();
        A0.b bVarW = cVar.w();
        if (bVarW instanceof E0.i) {
            try {
                MediaCrypto mediaCrypto = this.f3282W;
                mediaCrypto.getClass();
                ((E0.i) bVarW).getClass();
                mediaCrypto.setMediaDrmSession(null);
            } catch (MediaCryptoException e8) {
                throw f(e8, this.f3277R, false, 6006);
            }
        }
        l0(this.f3280U);
        this.f3253B0 = 0;
        this.f3254C0 = 0;
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x0034, code lost:
    
        if (r4 >= r0) goto L14;
     */
    @Override // B0.AbstractC0020g
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void t(C1579o[] c1579oArr, long j8, long j9, C c3) {
        if (this.f3272O0.f3249c == -9223372036854775807L) {
            m0(new s(-9223372036854775807L, j8, j9));
            return;
        }
        ArrayDeque arrayDeque = this.f3273P;
        if (arrayDeque.isEmpty()) {
            long j10 = this.f3258G0;
            if (j10 != -9223372036854775807L) {
                long j11 = this.f3274P0;
                if (j11 != -9223372036854775807L) {
                }
            }
            m0(new s(-9223372036854775807L, j8, j9));
            if (this.f3272O0.f3249c != -9223372036854775807L) {
                c0();
                return;
            }
            return;
        }
        arrayDeque.add(new s(this.f3258G0, j8, j9));
    }

    public final void t0(long j8) {
        C1579o c1579o = (C1579o) this.f3272O0.f3250d.f(j8);
        if (c1579o == null && this.f3276Q0 && this.f3287c0 != null) {
            c1579o = (C1579o) this.f3272O0.f3250d.e();
        }
        if (c1579o != null) {
            this.f3278S = c1579o;
        } else if (!this.f3288d0 || this.f3278S == null) {
            return;
        }
        C1579o c1579o2 = this.f3278S;
        c1579o2.getClass();
        Z(c1579o2, this.f3287c0);
        this.f3288d0 = false;
        this.f3276Q0 = false;
    }

    /* JADX WARN: Removed duplicated region for block: B:41:0x0078 A[LOOP:1: B:31:0x0053->B:41:0x0078, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0099 A[LOOP:2: B:42:0x0079->B:52:0x0099, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:87:0x0079 A[EDGE_INSN: B:87:0x0079->B:90:? BREAK  A[LOOP:1: B:31:0x0053->B:41:0x0078], SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:88:0x009a A[EDGE_INSN: B:88:0x009a->B:53:0x009a BREAK  A[LOOP:2: B:42:0x0079->B:52:0x0099], SYNTHETIC] */
    @Override // B0.AbstractC0020g
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void v(long j8, long j9) throws C0030q {
        boolean z8;
        boolean z9;
        boolean z10 = false;
        if (this.f3266L0) {
            this.f3266L0 = false;
            e0();
        }
        C0030q c0030q = this.f3268M0;
        if (c0030q != null) {
            this.f3268M0 = null;
            throw c0030q;
        }
        try {
            if (this.f3263J0) {
                i0();
                return;
            }
            if (this.f3277R != null || g0(2)) {
                S();
                if (this.f3306w0) {
                    Trace.beginSection("bypassRender");
                    while (A(j8, j9)) {
                    }
                    Trace.endSection();
                } else if (this.f3285a0 != null) {
                    this.f762w.getClass();
                    long jElapsedRealtime = SystemClock.elapsedRealtime();
                    Trace.beginSection("drainAndFeed");
                    while (F(j8, j9)) {
                        long j10 = this.X;
                        if (j10 != -9223372036854775807L) {
                            this.f762w.getClass();
                            if (SystemClock.elapsedRealtime() - jElapsedRealtime < j10) {
                                z9 = true;
                                if (!z9) {
                                    break;
                                }
                            } else {
                                z9 = false;
                                if (!z9) {
                                }
                            }
                        } else {
                            z9 = true;
                            if (!z9) {
                            }
                        }
                    }
                    while (G()) {
                        long j11 = this.X;
                        if (j11 != -9223372036854775807L) {
                            this.f762w.getClass();
                            if (SystemClock.elapsedRealtime() - jElapsedRealtime < j11) {
                                z8 = true;
                                if (!z8) {
                                    break;
                                }
                            } else {
                                z8 = false;
                                if (!z8) {
                                }
                            }
                        } else {
                            z8 = true;
                            if (!z8) {
                            }
                        }
                    }
                    Trace.endSection();
                } else {
                    C0021h c0021h = this.f3270N0;
                    int i = c0021h.f772d;
                    c0 c0Var = this.f764y;
                    c0Var.getClass();
                    c0021h.f772d = i + c0Var.m(j8 - this.f750A);
                    g0(1);
                }
                synchronized (this.f3270N0) {
                }
            }
        } catch (MediaCodec.CryptoException e8) {
            throw f(e8, this.f3277R, false, x0.v.v(e8.getErrorCode()));
        } catch (IllegalStateException e9) {
            boolean z11 = e9 instanceof MediaCodec.CodecException;
            if (!z11) {
                StackTraceElement[] stackTrace = e9.getStackTrace();
                if (stackTrace.length <= 0 || !stackTrace[0].getClassName().equals("android.media.MediaCodec")) {
                    throw e9;
                }
            }
            V(e9);
            if (z11 && ((MediaCodec.CodecException) e9).isRecoverable()) {
                z10 = true;
            }
            if (z10) {
                h0();
            }
            p pVarC = C(e9, this.f3292h0);
            throw f(pVarC, this.f3277R, z10, pVarC.f3233q == 1101 ? 4006 : 4003);
        }
    }

    @Override // B0.AbstractC0020g
    public void x(float f3, float f7) throws C0030q {
        this.f3283Y = f3;
        this.f3284Z = f7;
        r0(this.f3286b0);
    }

    @Override // B0.AbstractC0020g
    public final int y(C1579o c1579o) throws C0030q {
        try {
            return q0(this.f3260I, c1579o);
        } catch (w e8) {
            throw f(e8, c1579o, false, 4002);
        }
    }

    @Override // B0.AbstractC0020g
    public final int z() {
        return 8;
    }

    public void a0() {
    }

    public void d0(A0.h hVar) {
    }
}
