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

import androidx.annotation.Nullable;
import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor;
import java.io.EOFException;
import java.io.IOException;

/* JADX INFO: loaded from: classes2.dex */
public final class w7 implements b8 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final a8 f17884a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final long f17885b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final m2.k f17887d;

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

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

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

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

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

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

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

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

    public w7(m2.k kVar, long j10, long j11, long j12, long j13, boolean z10) {
        ih1.x(j10 >= 0 && j11 > j10);
        this.f17887d = kVar;
        this.f17885b = j10;
        this.f17886c = j11;
        if (j12 == j11 - j10 || z10) {
            this.f17889f = j13;
            this.f17888e = 4;
        } else {
            this.f17888e = 0;
        }
        this.f17884a = new a8();
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0027  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00ba A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00bb  */
    @Override // com.google.android.gms.internal.ads.b8
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long a(p2 p2Var) throws IOException {
        a8 a8Var;
        a8 a8Var2;
        long j10;
        long jMax;
        a8 a8Var3;
        int i10 = this.f17888e;
        long j11 = this.f17886c;
        a8 a8Var4 = this.f17884a;
        if (i10 == 0) {
            a8Var = a8Var4;
            long jZzn = p2Var.zzn();
            this.f17890g = jZzn;
            this.f17888e = 1;
            long j12 = (-65307) + j11;
            if (j12 > jZzn) {
                return j12;
            }
        } else if (i10 != 1) {
            if (i10 == 2) {
                long j13 = this.f17892i;
                long j14 = this.f17893j;
                if (j13 == j14) {
                    a8Var2 = a8Var4;
                    j10 = -1;
                    jMax = -1;
                    if (jMax != j10) {
                        return jMax;
                    }
                    this.f17888e = 3;
                    a8Var3 = a8Var2;
                } else {
                    long jZzn2 = p2Var.zzn();
                    if (a8Var4.a(p2Var, j14)) {
                        a8Var4.b(p2Var, false);
                        p2Var.zzl();
                        long j15 = this.f17891h;
                        long j16 = a8Var4.f8516b;
                        long j17 = j15 - j16;
                        int i11 = a8Var4.f8518d + a8Var4.f8519e;
                        if (j17 < 0 || j17 >= 72000) {
                            if (j17 < 0) {
                                this.f17893j = jZzn2;
                                this.f17895l = j16;
                            } else {
                                this.f17892i = p2Var.zzn() + ((long) i11);
                                this.f17894k = j16;
                            }
                            long j18 = this.f17893j;
                            long j19 = this.f17892i;
                            long j20 = j18 - j19;
                            if (j20 < SilenceSkippingAudioProcessor.DEFAULT_MINIMUM_SILENCE_DURATION_US) {
                                this.f17893j = j19;
                                jMax = j19;
                            } else {
                                a8Var2 = a8Var4;
                                long jZzn3 = ((j17 * j20) / (this.f17895l - this.f17894k)) + (p2Var.zzn() - (((long) i11) * (j17 <= 0 ? 2L : 1L)));
                                j10 = -1;
                                String str = bb1.f9474a;
                                jMax = Math.max(j19, Math.min(jZzn3, j18 - 1));
                            }
                        }
                        if (jMax != j10) {
                        }
                    } else {
                        long j21 = this.f17892i;
                        if (j21 == jZzn2) {
                            throw new IOException("No ogg page can be found.");
                        }
                        jMax = j21;
                    }
                    a8Var2 = a8Var4;
                    j10 = -1;
                    if (jMax != j10) {
                    }
                }
            } else {
                if (i10 != 3) {
                    return -1L;
                }
                a8Var3 = a8Var4;
                j10 = -1;
            }
            while (true) {
                a8Var3.a(p2Var, j10);
                a8Var3.b(p2Var, false);
                if (a8Var3.f8516b > this.f17891h) {
                    p2Var.zzl();
                    this.f17888e = 4;
                    return -(this.f17894k + 2);
                }
                p2Var.e(a8Var3.f8518d + a8Var3.f8519e);
                this.f17892i = p2Var.zzn();
                this.f17894k = a8Var3.f8516b;
                j10 = -1;
            }
        } else {
            a8Var = a8Var4;
        }
        a8Var.f8515a = 0;
        a8Var.f8516b = 0L;
        a8Var.f8517c = 0;
        a8Var.f8518d = 0;
        a8Var.f8519e = 0;
        if (!a8Var.a(p2Var, -1L)) {
            throw new EOFException();
        }
        a8Var.b(p2Var, false);
        p2Var.e(a8Var.f8518d + a8Var.f8519e);
        long j22 = a8Var.f8516b;
        while ((a8Var.f8515a & 4) != 4 && a8Var.a(p2Var, -1L) && p2Var.zzn() < j11 && a8Var.b(p2Var, true)) {
            try {
                p2Var.e(a8Var.f8518d + a8Var.f8519e);
                j22 = a8Var.f8516b;
            } catch (EOFException unused) {
            }
        }
        this.f17889f = j22;
        this.f17888e = 4;
        return this.f17890g;
    }

    @Override // com.google.android.gms.internal.ads.b8
    public final void c(long j10) {
        long j11 = this.f17889f - 1;
        String str = bb1.f9474a;
        this.f17891h = Math.max(0L, Math.min(j10, j11));
        this.f17888e = 2;
        this.f17892i = this.f17885b;
        this.f17893j = this.f17886c;
        this.f17894k = 0L;
        this.f17895l = this.f17889f;
    }

    @Override // com.google.android.gms.internal.ads.b8
    @Nullable
    public final /* bridge */ /* synthetic */ k3 zzc() {
        if (this.f17889f != 0) {
            return new v7(this);
        }
        return null;
    }
}
