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

import androidx.media3.common.MimeTypes;
import java.io.EOFException;
import java.io.InterruptedIOException;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final p01 f11129c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final androidx.media3.extractor.b1 f11130d;

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

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

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ga f11127a = new ga(true, null, 0, MimeTypes.AUDIO_AAC);

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public long f11133g = -1;

    public fa() {
        p01 p01Var = new p01(10);
        this.f11129c = p01Var;
        byte[] bArr = p01Var.f15225a;
        this.f11130d = new androidx.media3.extractor.b1(bArr, bArr.length);
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final boolean a(p2 p2Var) throws EOFException, InterruptedIOException {
        p01 p01Var;
        int i10 = 0;
        while (true) {
            p01Var = this.f11129c;
            h2 h2Var = (h2) p2Var;
            h2Var.j(p01Var.f15225a, 0, 10, false);
            p01Var.C(0);
            if (p01Var.M() != 4801587) {
                break;
            }
            p01Var.E(3);
            int iG = p01Var.g();
            i10 += iG + 10;
            h2Var.l(iG, false);
        }
        p2Var.zzl();
        h2 h2Var2 = (h2) p2Var;
        h2Var2.l(i10, false);
        if (this.f11133g == -1) {
            this.f11133g = i10;
        }
        int i11 = 0;
        int i12 = 0;
        int i13 = i10;
        do {
            h2Var2.j(p01Var.f15225a, 0, 2, false);
            p01Var.C(0);
            if ((p01Var.J() & 65526) == 65520) {
                i11++;
                if (i11 >= 4 && i12 > 188) {
                    return true;
                }
                h2Var2.j(p01Var.f15225a, 0, 4, false);
                androidx.media3.extractor.b1 b1Var = this.f11130d;
                b1Var.l(14);
                int iP = b1Var.p(13);
                if (iP <= 6) {
                    i13++;
                    p2Var.zzl();
                    h2Var2.l(i13, false);
                } else {
                    h2Var2.l(iP - 6, false);
                    i12 += iP;
                }
            } else {
                i13++;
                p2Var.zzl();
                h2Var2.l(i13, false);
            }
            i11 = 0;
            i12 = 0;
        } while (i13 - i10 < 8192);
        return false;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void b(q2 q2Var) {
        this.f11131e = q2Var;
        this.f11127a.a(q2Var, new x2.o0(Integer.MIN_VALUE, 0, 1, 1));
        q2Var.d();
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final int c(p2 p2Var, androidx.media3.extractor.f0 f0Var) throws zzat {
        this.f11131e.getClass();
        p01 p01Var = this.f11128b;
        int iD = p2Var.d(p01Var.f15225a, 0, 2048);
        if (!this.f11135i) {
            this.f11131e.k(new w2(-9223372036854775807L, 0L));
            this.f11135i = true;
        }
        if (iD == -1) {
            return -1;
        }
        p01Var.C(0);
        p01Var.A(iD);
        boolean z10 = this.f11134h;
        ga gaVar = this.f11127a;
        if (!z10) {
            gaVar.f11661t = this.f11132f;
            this.f11134h = true;
        }
        gaVar.d(p01Var);
        return 0;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        this.f11134h = false;
        this.f11127a.zza();
        this.f11132f = j11;
    }

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