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

import java.io.EOFException;
import java.io.InterruptedIOException;

/* JADX INFO: loaded from: classes2.dex */
public final class o4 implements o2 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final p01 f14827a = new p01(4);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final p01 f14828b = new p01(9);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final p01 f14829c = new p01(11);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final p01 f14830d = new p01();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final p4 f14831e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public q2 f14832f;

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

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

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

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

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

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

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

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

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

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

    public o4() {
        p4 p4Var = new p4(new m2());
        p4Var.f15255b = -9223372036854775807L;
        p4Var.f15256c = new long[0];
        p4Var.f15257d = new long[0];
        this.f14831e = p4Var;
        this.f14833g = 1;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final boolean a(p2 p2Var) throws EOFException, InterruptedIOException {
        p01 p01Var = this.f14827a;
        h2 h2Var = (h2) p2Var;
        h2Var.j(p01Var.f15225a, 0, 3, false);
        p01Var.C(0);
        if (p01Var.M() != 4607062) {
            return false;
        }
        h2Var.j(p01Var.f15225a, 0, 2, false);
        p01Var.C(0);
        if ((p01Var.J() & 250) != 0) {
            return false;
        }
        h2Var.j(p01Var.f15225a, 0, 4, false);
        p01Var.C(0);
        int iB = p01Var.b();
        p2Var.zzl();
        h2 h2Var2 = (h2) p2Var;
        h2Var2.l(iB, false);
        h2Var2.j(p01Var.f15225a, 0, 4, false);
        p01Var.C(0);
        return p01Var.b() == 0;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void b(q2 q2Var) {
        this.f14832f = q2Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:49:0x00c3 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00cd  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x00d9 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:92:0x0009 A[SYNTHETIC] */
    @Override // com.google.android.gms.internal.ads.o2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int c(p2 p2Var, androidx.media3.extractor.f0 f0Var) throws zzat {
        boolean z10;
        boolean zJ0;
        this.f14832f.getClass();
        while (true) {
            int i10 = this.f14833g;
            int i11 = 8;
            if (i10 == 1) {
                p01 p01Var = this.f14828b;
                if (!p2Var.i(p01Var.f15225a, 0, 9, true)) {
                    return -1;
                }
                p01Var.C(0);
                p01Var.E(4);
                int I = p01Var.I();
                int i12 = I & 4;
                int i13 = I & 1;
                if (i12 != 0 && this.f14841o == null) {
                    this.f14841o = new n4(this.f14832f.e(8, 1));
                }
                if (i13 != 0 && this.f14842p == null) {
                    this.f14842p = new q4(this.f14832f.e(9, 2));
                }
                this.f14832f.d();
                this.f14836j = p01Var.b() - 5;
                this.f14833g = 2;
            } else if (i10 == 2) {
                p2Var.e(this.f14836j);
                this.f14836j = 0;
                this.f14833g = 3;
            } else if (i10 == 3) {
                p01 p01Var2 = this.f14829c;
                if (!p2Var.i(p01Var2.f15225a, 0, 11, true)) {
                    return -1;
                }
                p01Var2.C(0);
                this.f14837k = p01Var2.I();
                this.f14838l = p01Var2.M();
                this.f14839m = p01Var2.M();
                this.f14839m = (this.f14839m | ((long) (p01Var2.I() << 24))) * 1000;
                p01Var2.E(3);
                this.f14833g = 4;
            } else {
                if (i10 != 4) {
                    throw new IllegalStateException();
                }
                boolean z11 = this.f14834h;
                p4 p4Var = this.f14831e;
                long j10 = z11 ? this.f14835i + this.f14839m : p4Var.f15255b == -9223372036854775807L ? 0L : this.f14839m;
                int i14 = this.f14837k;
                if (i14 == 8) {
                    if (this.f14841o != null) {
                        if (!this.f14840n) {
                            this.f14832f.k(new w2(-9223372036854775807L, 0L));
                            this.f14840n = true;
                        }
                        n4 n4Var = this.f14841o;
                        p01 p01VarE = e(p2Var);
                        n4Var.I0(p01VarE);
                        zJ0 = n4Var.J0(j10, p01VarE);
                    }
                    z10 = true;
                    if (!this.f14834h && zJ0) {
                        this.f14834h = true;
                        this.f14835i = p4Var.f15255b == -9223372036854775807L ? -this.f14839m : 0L;
                    }
                    this.f14836j = 4;
                    this.f14833g = 2;
                    if (!z10) {
                        return 0;
                    }
                } else {
                    i11 = i14;
                }
                if (i11 != 9) {
                    if (i11 == 18 && !this.f14840n) {
                        p01 p01VarE2 = e(p2Var);
                        p4Var.getClass();
                        p4Var.I0(j10, p01VarE2);
                        long j11 = p4Var.f15255b;
                        if (j11 != -9223372036854775807L) {
                            this.f14832f.k(new h3(j11, p4Var.f15257d, p4Var.f15256c));
                            this.f14840n = true;
                        }
                        z10 = true;
                        zJ0 = false;
                    }
                    if (!this.f14834h) {
                    }
                    this.f14836j = 4;
                    this.f14833g = 2;
                    if (!z10) {
                    }
                } else if (this.f14842p != null) {
                    if (!this.f14840n) {
                        this.f14832f.k(new w2(-9223372036854775807L, 0L));
                        this.f14840n = true;
                    }
                    q4 q4Var = this.f14842p;
                    p01 p01VarE3 = e(p2Var);
                    zJ0 = q4Var.I0(p01VarE3) && q4Var.J0(j10, p01VarE3);
                    z10 = true;
                    if (!this.f14834h) {
                        this.f14834h = true;
                        this.f14835i = p4Var.f15255b == -9223372036854775807L ? -this.f14839m : 0L;
                    }
                    this.f14836j = 4;
                    this.f14833g = 2;
                    if (!z10) {
                    }
                }
                p2Var.e(this.f14838l);
                zJ0 = false;
                z10 = false;
                if (!this.f14834h) {
                }
                this.f14836j = 4;
                this.f14833g = 2;
                if (!z10) {
                }
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        if (j10 == 0) {
            this.f14833g = 1;
            this.f14834h = false;
        } else {
            this.f14833g = 3;
        }
        this.f14836j = 0;
    }

    public final p01 e(p2 p2Var) {
        int i10 = this.f14838l;
        p01 p01Var = this.f14830d;
        byte[] bArr = p01Var.f15225a;
        if (i10 > bArr.length) {
            int length = bArr.length;
            p01Var.w(0, new byte[Math.max(length + length, i10)]);
        } else {
            p01Var.C(0);
        }
        p01Var.A(this.f14838l);
        p2Var.c(p01Var.f15225a, 0, this.f14838l);
        return p01Var;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void zzf() {
    }
}
