package m2;

import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.extractor.z;
import com.google.android.gms.internal.ads.a8;
import com.google.android.gms.internal.ads.p01;
import com.google.android.gms.internal.ads.p2;
import java.io.EOFException;

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

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

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

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

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

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

    public f(int i10) {
        if (i10 != 1) {
            this.f30313d = new g();
            this.f30314e = new ParsableByteArray(new byte[65025], 0);
            this.f30310a = -1;
        } else {
            this.f30313d = new a8();
            this.f30314e = new p01(new byte[65025], 0);
            this.f30310a = -1;
        }
    }

    public final int a(int i10) {
        int i11;
        int i12 = 0;
        this.f30311b = 0;
        do {
            int i13 = this.f30311b;
            int i14 = i10 + i13;
            Object obj = this.f30313d;
            if (i14 >= ((g) obj).f30317c) {
                break;
            }
            int[] iArr = ((g) obj).f30320f;
            this.f30311b = i13 + 1;
            i11 = iArr[i13 + i10];
            i12 += i11;
        } while (i11 == 255);
        return i12;
    }

    public final boolean b(z zVar) {
        int i10;
        Assertions.checkState(zVar != null);
        boolean z10 = this.f30312c;
        Object obj = this.f30314e;
        if (z10) {
            this.f30312c = false;
            ((ParsableByteArray) obj).reset(0);
        }
        while (!this.f30312c) {
            int i11 = this.f30310a;
            Object obj2 = this.f30313d;
            if (i11 < 0) {
                g gVar = (g) obj2;
                if (gVar.b(zVar, -1L) && gVar.a(zVar, true)) {
                    int iA = gVar.f30318d;
                    if ((gVar.f30315a & 1) == 1 && ((ParsableByteArray) obj).limit() == 0) {
                        iA += a(0);
                        i10 = this.f30311b;
                    } else {
                        i10 = 0;
                    }
                    try {
                        zVar.k(iA);
                        this.f30310a = i10;
                    } catch (EOFException unused) {
                    }
                }
                return false;
            }
            int iA2 = a(this.f30310a);
            int i12 = this.f30310a + this.f30311b;
            if (iA2 > 0) {
                ParsableByteArray parsableByteArray = (ParsableByteArray) obj;
                parsableByteArray.ensureCapacity(parsableByteArray.limit() + iA2);
                try {
                    zVar.readFully(parsableByteArray.getData(), parsableByteArray.limit(), iA2);
                    parsableByteArray.setLimit(parsableByteArray.limit() + iA2);
                    this.f30312c = ((g) obj2).f30320f[i12 + (-1)] != 255;
                } catch (EOFException unused2) {
                    return false;
                }
            }
            if (i12 == ((g) obj2).f30317c) {
                i12 = -1;
            }
            this.f30310a = i12;
        }
        return true;
    }

    public final boolean c(p2 p2Var) {
        boolean z10 = this.f30312c;
        Object obj = this.f30314e;
        if (z10) {
            this.f30312c = false;
            ((p01) obj).v(0);
        }
        while (true) {
            if (this.f30312c) {
                return true;
            }
            int i10 = this.f30310a;
            Object obj2 = this.f30313d;
            if (i10 < 0) {
                a8 a8Var = (a8) obj2;
                if (!a8Var.a(p2Var, -1L) || !a8Var.b(p2Var, true)) {
                    break;
                }
                int iD = a8Var.f8518d;
                if ((a8Var.f8515a & 1) == 1 && ((p01) obj).f15227c == 0) {
                    iD += d(0);
                    i10 = this.f30311b;
                } else {
                    i10 = 0;
                }
                try {
                    p2Var.e(iD);
                    this.f30310a = i10;
                } catch (EOFException unused) {
                }
            }
            int iD2 = d(i10);
            int i11 = this.f30310a + this.f30311b;
            if (iD2 > 0) {
                p01 p01Var = (p01) obj;
                p01Var.x(p01Var.f15227c + iD2);
                try {
                    p2Var.c(p01Var.f15225a, p01Var.f15227c, iD2);
                    p01Var.A(p01Var.f15227c + iD2);
                    this.f30312c = ((a8) obj2).f8520f[i11 + (-1)] != 255;
                } catch (EOFException unused2) {
                    return false;
                }
            }
            if (i11 == ((a8) obj2).f8517c) {
                i11 = -1;
            }
            this.f30310a = i11;
        }
        return false;
    }

    public final int d(int i10) {
        int i11;
        int i12 = 0;
        this.f30311b = 0;
        do {
            int i13 = this.f30311b;
            int i14 = i10 + i13;
            a8 a8Var = (a8) this.f30313d;
            if (i14 >= a8Var.f8517c) {
                break;
            }
            this.f30311b = i13 + 1;
            i11 = a8Var.f8520f[i14];
            i12 += i11;
        } while (i11 == 255);
        return i12;
    }
}
