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

import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.io.EOFException;
import java.io.IOException;
import java.math.RoundingMode;

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final /* synthetic */ int f13962p = 0;

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

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

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

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

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

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

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

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

    @Nullable
    private ta zzk;

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public long f13971i = -9223372036854775807L;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public u3 f13969g = new m2();

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

    @Override // com.google.android.gms.internal.ads.o2
    public final boolean a(p2 p2Var) {
        return e(p2Var, true);
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void b(q2 q2Var) {
        this.f13967e = q2Var;
        u3 u3VarE = q2Var.e(0, 1);
        this.f13968f = u3VarE;
        this.f13969g = u3VarE;
        this.f13967e.d();
    }

    /* JADX WARN: Removed duplicated region for block: B:116:0x02e7  */
    /* JADX WARN: Removed duplicated region for block: B:117:0x02e9  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x0061  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x0074  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x008b  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0116  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x0125  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x0188  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x018b  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x01a4  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x01aa  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x01c3  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x01cc  */
    /* JADX WARN: Removed duplicated region for block: B:90:0x024d  */
    @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 IOException {
        i3 i3Var;
        p01 p01Var;
        int iE;
        e3 e3Var;
        p01 p01Var2;
        long j10;
        o6 j6Var;
        int i10;
        int i11;
        ta taVar;
        long jZzn;
        r5 r5Var;
        k6 k6VarB;
        o6 n6Var;
        this.f13968f.getClass();
        String str = bb1.f9474a;
        if (this.f13970h == 0) {
            try {
                e(p2Var, false);
            } catch (EOFException unused) {
                return -1;
            }
        }
        o6 o6Var = this.f13976n;
        i3 i3Var2 = this.f13964b;
        p01 p01Var3 = this.f13963a;
        if (o6Var == null) {
            p01 p01Var4 = new p01(i3Var2.f12347b);
            p2Var.h(0, i3Var2.f12347b, p01Var4.D());
            int i12 = 21;
            if ((i3Var2.f12346a & 1) != 0) {
                if (i3Var2.f12349d != 1) {
                    i12 = 36;
                }
            } else if (i3Var2.f12349d == 1) {
                i12 = 13;
            }
            if (p01Var4.z() >= i12 + 4) {
                p01Var4.C(i12);
                int iB = p01Var4.b();
                if (iB != 1483304551) {
                    if (iB == 1231971951) {
                        iB = 1231971951;
                    } else if (p01Var4.z() >= 40) {
                        p01Var4.C(36);
                        iB = p01Var4.b() == 1447187017 ? 1447187017 : 0;
                    }
                }
                e3 e3Var2 = this.f13965c;
                o6 j6Var2 = null;
                if (iB == 1231971951) {
                    q6 q6VarA = q6.a(i3Var2, p01Var4);
                    if (!e3Var2.b() && (i10 = q6VarA.f15596d) != -1 && (i11 = q6VarA.f15597e) != -1) {
                        e3Var2.f10608a = i10;
                        e3Var2.f10609b = i11;
                    }
                    long jZzn2 = p2Var.zzn();
                    long jZzo = p2Var.zzo();
                    long j11 = q6VarA.f15595c;
                    if (jZzo == -1 || j11 == -1) {
                        e3Var = e3Var2;
                        i3Var = i3Var2;
                        p01Var2 = p01Var3;
                        p2Var.e(i3Var.f12347b);
                        if (iB != 1483304551) {
                            j6Var = r6.zzd(q6VarA, jZzn2);
                        } else {
                            long jZzo2 = p2Var.zzo();
                            long jB = q6VarA.b();
                            if (jB == -9223372036854775807L) {
                                j6Var = null;
                            } else {
                                i3 i3Var3 = q6VarA.f15593a;
                                if (j11 != -1) {
                                    jZzo2 = jZzn2 + j11;
                                    j10 = j11 - ((long) i3Var3.f12347b);
                                } else {
                                    if (jZzo2 != -1) {
                                        j10 = (jZzo2 - jZzn2) - ((long) i3Var3.f12347b);
                                    }
                                    j6Var = null;
                                }
                                long j12 = jZzo2;
                                RoundingMode roundingMode = RoundingMode.HALF_UP;
                                j6Var = new j6(za2.b(bb1.r(j10, 8000000L, jB, roundingMode)), za2.b(ih1.f(j10, q6VarA.f15594b, roundingMode)), j12, jZzn2 + ((long) i3Var3.f12347b));
                            }
                        }
                        taVar = this.zzk;
                        jZzn = p2Var.zzn();
                        if (taVar != null && (r5Var = (r5) taVar.zzc(r5.class, zzgrf.f19748a)) != null) {
                            t5 t5Var = (t5) taVar.zzc(t5.class, l6.f13507a);
                            k6VarB = k6.b(jZzn, r5Var, t5Var != null ? -9223372036854775807L : bb1.p(Long.parseLong((String) t5Var.f16724b.get(0))));
                        } else {
                            k6VarB = null;
                        }
                        if (this.f13977o) {
                            if (k6VarB != null) {
                                j6Var2 = k6VarB;
                            } else if (j6Var != null) {
                                j6Var2 = j6Var;
                            }
                            if (j6Var2 == null) {
                                p2Var.h(0, 4, p01Var2.D());
                                p01Var = p01Var2;
                                p01Var.C(0);
                                i3Var.a(p01Var.b());
                                j6Var2 = new j6(i3Var.f12350e, i3Var.f12347b, p2Var.zzo(), p2Var.zzn());
                            } else {
                                p01Var = p01Var2;
                            }
                            u3 u3Var = this.f13968f;
                            j6Var2.zza();
                            u3Var.zzN();
                            n6Var = j6Var2;
                        } else {
                            n6Var = new n6();
                            p01Var = p01Var2;
                        }
                        this.f13976n = n6Var;
                        this.f13967e.k(n6Var);
                        sm2 sm2Var = new sm2();
                        sm2Var.zzl(MimeTypes.AUDIO_MPEG);
                        sm2Var.zzm(i3Var.zzb);
                        sm2Var.s();
                        sm2Var.a(i3Var.f12349d);
                        sm2Var.b(i3Var.f12348c);
                        e3 e3Var3 = e3Var;
                        sm2Var.c(e3Var3.f10608a);
                        sm2Var.d(e3Var3.f10609b);
                        sm2Var.zzk(this.zzk);
                        if (this.f13976n.zzg() != -2147483647) {
                            sm2Var.r(this.f13976n.zzg());
                        }
                        this.f13969g.d(sm2Var.e());
                        this.f13973k = p2Var.zzn();
                    } else {
                        long j13 = jZzn2 + j11;
                        if (p2Var.zzo() != j13) {
                            i3Var = i3Var2;
                            long jZzo3 = p2Var.zzo();
                            e3Var = e3Var2;
                            StringBuilder sb = new StringBuilder(String.valueOf(j13).length() + String.valueOf(jZzo3).length() + 53 + 20);
                            p01Var2 = p01Var3;
                            defpackage.e.B(sb, "Data size mismatch between stream (", jZzo3, ") and Xing frame (");
                            sb.append(j13);
                            sb.append("), using Xing value.");
                            vt0.b(sb.toString());
                        }
                        p2Var.e(i3Var.f12347b);
                        if (iB != 1483304551) {
                        }
                        taVar = this.zzk;
                        jZzn = p2Var.zzn();
                        if (taVar != null) {
                            t5 t5Var2 = (t5) taVar.zzc(t5.class, l6.f13507a);
                            k6VarB = k6.b(jZzn, r5Var, t5Var2 != null ? -9223372036854775807L : bb1.p(Long.parseLong((String) t5Var2.f16724b.get(0))));
                            if (this.f13977o) {
                            }
                            this.f13976n = n6Var;
                            this.f13967e.k(n6Var);
                            sm2 sm2Var2 = new sm2();
                            sm2Var2.zzl(MimeTypes.AUDIO_MPEG);
                            sm2Var2.zzm(i3Var.zzb);
                            sm2Var2.s();
                            sm2Var2.a(i3Var.f12349d);
                            sm2Var2.b(i3Var.f12348c);
                            e3 e3Var32 = e3Var;
                            sm2Var2.c(e3Var32.f10608a);
                            sm2Var2.d(e3Var32.f10609b);
                            sm2Var2.zzk(this.zzk);
                            if (this.f13976n.zzg() != -2147483647) {
                            }
                            this.f13969g.d(sm2Var2.e());
                            this.f13973k = p2Var.zzn();
                        }
                    }
                } else if (iB != 1447187017) {
                    if (iB != 1483304551) {
                        p2Var.zzl();
                        e3Var = e3Var2;
                        i3Var = i3Var2;
                        p01Var2 = p01Var3;
                    }
                    j6Var = null;
                    taVar = this.zzk;
                    jZzn = p2Var.zzn();
                    if (taVar != null) {
                    }
                } else {
                    i3Var = i3Var2;
                    j6Var = p6.zzd(p2Var.zzo(), p2Var.zzn(), i3Var, p01Var4);
                    p2Var.e(i3Var2.f12347b);
                    e3Var = e3Var2;
                    p01Var2 = p01Var3;
                    taVar = this.zzk;
                    jZzn = p2Var.zzn();
                    if (taVar != null) {
                    }
                }
            }
        } else {
            i3Var = i3Var2;
            p01Var = p01Var3;
            long j14 = this.f13973k;
            if (j14 != 0) {
                long jZzn3 = p2Var.zzn();
                if (jZzn3 < j14) {
                    p2Var.e((int) (j14 - jZzn3));
                }
            }
        }
        int i13 = this.f13975m;
        if (i13 == 0) {
            p2Var.zzl();
            if (f(p2Var)) {
                return -1;
            }
            p01Var.C(0);
            int iB2 = p01Var.b();
            if (((-128000) & iB2) != (((long) this.f13970h) & (-128000)) || za2.a(iB2) == -1) {
                p2Var.e(1);
                this.f13970h = 0;
            } else {
                i3Var.a(iB2);
                if (this.f13971i == -9223372036854775807L) {
                    this.f13971i = this.f13976n.a(p2Var.zzn());
                }
                i13 = i3Var.f12347b;
                this.f13975m = i13;
                this.f13974l = p2Var.zzn() + ((long) i13);
                iE = this.f13969g.e(p2Var, i13, true);
                if (iE != -1) {
                    return -1;
                }
                int i14 = this.f13975m - iE;
                this.f13975m = i14;
                if (i14 <= 0) {
                    this.f13969g.zze(((this.f13972j * 1000000) / ((long) i3Var.f12348c)) + this.f13971i, 1, i3Var.f12347b, 0, null);
                    this.f13972j += (long) i3Var.f12351f;
                    this.f13975m = 0;
                    return 0;
                }
            }
        } else {
            iE = this.f13969g.e(p2Var, i13, true);
            if (iE != -1) {
            }
        }
        return 0;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        this.f13970h = 0;
        this.f13971i = -9223372036854775807L;
        this.f13972j = 0L;
        this.f13975m = 0;
        this.f13974l = -1L;
    }

    public final boolean e(p2 p2Var, boolean z10) throws IOException {
        int iZzm;
        int i10;
        int iA;
        p2Var.zzl();
        if (p2Var.zzn() == 0) {
            ta taVarZza = this.f13966d.zza(p2Var, null, 131072);
            this.zzk = taVarZza;
            if (taVarZza != null) {
                this.f13965c.a(taVarZza);
            }
            iZzm = (int) p2Var.zzm();
            if (!z10) {
                p2Var.e(iZzm);
            }
            i10 = 0;
        } else {
            iZzm = 0;
            i10 = 0;
        }
        int i11 = i10;
        int i12 = i11;
        while (true) {
            if (!f(p2Var)) {
                p01 p01Var = this.f13963a;
                p01Var.C(0);
                int iB = p01Var.b();
                if ((i10 == 0 || ((-128000) & iB) == (((long) i10) & (-128000))) && (iA = za2.a(iB)) != -1) {
                    i11++;
                    if (i11 != 1) {
                        if (i11 == 4) {
                            break;
                        }
                    } else {
                        this.f13964b.a(iB);
                        i10 = iB;
                    }
                    p2Var.a(iA - 4);
                } else {
                    int i13 = i12 + 1;
                    if (i12 == 131072) {
                        if (z10) {
                            return false;
                        }
                        g();
                        throw new EOFException();
                    }
                    if (z10) {
                        p2Var.zzl();
                        p2Var.a(iZzm + i13);
                    } else {
                        p2Var.e(1);
                    }
                    i11 = 0;
                    i12 = i13;
                    i10 = 0;
                }
            } else if (i11 <= 0) {
                g();
                throw new EOFException();
            }
        }
        if (z10) {
            p2Var.e(iZzm + i12);
        } else {
            p2Var.zzl();
        }
        this.f13970h = i10;
        return true;
    }

    public final boolean f(p2 p2Var) {
        o6 o6Var = this.f13976n;
        if (o6Var != null) {
            long jZzf = o6Var.zzf();
            if (jZzf != -1 && p2Var.zzm() > jZzf - 4) {
                return true;
            }
        }
        try {
            return !p2Var.j(this.f13963a.f15225a, 0, 4, true);
        } catch (EOFException unused) {
            return true;
        }
    }

    public final void g() {
        o6 o6Var = this.f13976n;
        if ((o6Var instanceof j6) && o6Var.zzb()) {
            long j10 = this.f13974l;
            if (j10 == -1 || j10 == this.f13976n.zzf()) {
                return;
            }
            j6 j6Var = (j6) this.f13976n;
            this.f13976n = new j6(j6Var.f12718h, j6Var.f12719i, this.f13974l, j6Var.f12717g);
            q2 q2Var = this.f13967e;
            q2Var.getClass();
            q2Var.k(this.f13976n);
            this.f13968f.getClass();
            this.f13976n.zza();
        }
    }

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