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

import android.content.Context;
import android.os.SystemClock;
import android.view.Surface;
import androidx.annotation.Nullable;
import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor;
import androidx.media3.exoplayer.dash.DashMediaSource;

/* JADX INFO: loaded from: classes2.dex */
public final class d1 {

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f10129d = 0;

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public float f10135j = 1.0f;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public sl0 f10136k = sl0.f16474a;

    public d1(Context context, c1 c1Var) {
        this.f10126a = c1Var;
        this.f10127b = new i1(context);
    }

    public final void a(int i10) {
        if (i10 == 0) {
            this.f10129d = 1;
        } else if (i10 != 1) {
            this.f10129d = Math.min(this.f10129d, 2);
        } else {
            this.f10129d = 0;
        }
        this.f10127b.d();
    }

    public final void b(float f10) {
        i1 i1Var = this.f10127b;
        i1Var.f12304d = f10;
        l0 l0Var = i1Var.f12301a;
        l0Var.f13442a.a();
        l0Var.f13443b.a();
        l0Var.f13444c = false;
        l0Var.f13445d = -9223372036854775807L;
        l0Var.f13446e = 0;
        i1Var.e();
    }

    public final boolean c(boolean z10) {
        if (z10 && (this.f10129d == 3 || (!this.f10137l && this.f10138m))) {
            this.f10133h = -9223372036854775807L;
            return true;
        }
        if (this.f10133h == -9223372036854775807L) {
            return false;
        }
        ((h71) this.f10136k).getClass();
        if (SystemClock.elapsedRealtime() < this.f10133h) {
            return true;
        }
        this.f10133h = -9223372036854775807L;
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x007d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int d(long j10, long j11, long j12, long j13, boolean z10, boolean z11, androidx.emoji2.text.l0 l0Var) {
        l0Var.f2247b = -9223372036854775807L;
        l0Var.f2248c = -9223372036854775807L;
        if (this.f10128c && this.f10130e == -9223372036854775807L) {
            this.f10130e = j11;
        }
        long j14 = this.f10132g;
        i1 i1Var = this.f10127b;
        if (j14 != j10) {
            long j15 = i1Var.f12312l;
            if (j15 != -1) {
                i1Var.f12315o = j15;
                i1Var.f12316p = i1Var.f12313m;
                i1Var.f12317q = i1Var.f12314n;
                i1Var.f12309i = i1Var.f12310j;
            }
            i1Var.f12311k++;
            long j16 = j10 * 1000;
            l0 l0Var2 = i1Var.f12301a;
            l0Var2.f13442a.c(j16);
            if (l0Var2.f13442a.b()) {
                l0Var2.f13444c = false;
            } else if (l0Var2.f13445d != -9223372036854775807L) {
                if (l0Var2.f13444c) {
                    k0 k0Var = l0Var2.f13443b;
                    long j17 = k0Var.f13053d;
                    if (j17 != 0) {
                        if (k0Var.f13056g[(int) ((j17 - 1) % 15)]) {
                            l0Var2.f13443b.a();
                            l0Var2.f13443b.c(l0Var2.f13445d);
                        }
                    }
                    l0Var2.f13444c = true;
                    l0Var2.f13443b.c(j16);
                }
            }
            if (l0Var2.f13444c && l0Var2.f13443b.b()) {
                k0 k0Var2 = l0Var2.f13442a;
                l0Var2.f13442a = l0Var2.f13443b;
                l0Var2.f13443b = k0Var2;
                l0Var2.f13444c = false;
            }
            l0Var2.f13445d = j16;
            l0Var2.f13446e = l0Var2.f13442a.b() ? 0 : l0Var2.f13446e + 1;
            i1Var.e();
            this.f10132g = j10;
        }
        long jP = (long) ((j10 - j11) / ((double) this.f10135j));
        if (this.f10128c) {
            ((h71) this.f10136k).getClass();
            jP -= bb1.p(SystemClock.elapsedRealtime()) - j12;
        }
        l0Var.f2247b = jP;
        if (z10 && !z11) {
            return 3;
        }
        boolean z12 = this.f10137l;
        c1 c1Var = this.f10126a;
        if (!z12) {
            if (((r0) c1Var).t0(jP, j11, z11, true)) {
                return 4;
            }
            if (this.f10128c && l0Var.f2247b < DashMediaSource.DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS) {
                return 3;
            }
            this.f10138m = true;
            return 5;
        }
        if (this.f10133h == -9223372036854775807L || this.f10134i) {
            int i10 = this.f10129d;
            if (i10 != 0) {
                if (i10 == 1) {
                    return 0;
                }
                if (i10 != 2) {
                    if (i10 != 3) {
                        throw new IllegalStateException();
                    }
                    ((h71) this.f10136k).getClass();
                    long jP2 = bb1.p(SystemClock.elapsedRealtime()) - this.f10131f;
                    if (this.f10128c) {
                        long j18 = this.f10130e;
                        if (j18 != -9223372036854775807L && j18 != j11 && jP < -30000 && jP2 > SilenceSkippingAudioProcessor.DEFAULT_MINIMUM_SILENCE_DURATION_US) {
                            return 0;
                        }
                    }
                } else if (j11 >= j13) {
                    return 0;
                }
            } else if (this.f10128c) {
                return 0;
            }
        }
        if (!this.f10128c || j11 == this.f10130e) {
            return 5;
        }
        ((h71) this.f10136k).getClass();
        long jNanoTime = System.nanoTime();
        long jC = i1Var.c((l0Var.f2247b * 1000) + jNanoTime, j10);
        l0Var.f2248c = jC;
        long j19 = (jC - jNanoTime) / 1000;
        l0Var.f2247b = j19;
        boolean z13 = (this.f10133h == -9223372036854775807L || this.f10134i) ? false : true;
        if (((r0) c1Var).t0(j19, j11, z11, z13)) {
            return 4;
        }
        long j20 = l0Var.f2247b;
        return (j20 >= -30000 || z11) ? j20 > 50000 ? 5 : 1 : z13 ? 3 : 2;
    }

    public final void e(float f10) {
        ih1.x(f10 > 0.0f);
        if (f10 == this.f10135j) {
            return;
        }
        this.f10135j = f10;
        i1 i1Var = this.f10127b;
        i1Var.f12307g = f10;
        i1Var.f(false);
    }

    public final void zzd(@Nullable Surface surface) {
        this.f10137l = surface != null;
        this.f10138m = false;
        this.f10127b.zzc(surface);
        this.f10129d = Math.min(this.f10129d, 1);
    }
}
