package R0;

import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.SystemClock;
import x0.AbstractC1709a;

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public x0.q f5993l = x0.q.f18545a;

    public v(Context context, j jVar, long j8) {
        this.f5983a = jVar;
        this.f5985c = j8;
        this.f5984b = new y(context);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00ae  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00b0  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0115  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int a(long j8, long j9, long j10, long j11, boolean z8, boolean z9, u uVar) {
        long j12;
        long j13;
        long j14;
        boolean z10;
        int i;
        long j15;
        int i5;
        int i8;
        long j16;
        long j17;
        uVar.f5981a = -9223372036854775807L;
        uVar.f5982b = -9223372036854775807L;
        if (this.f5988f == -9223372036854775807L) {
            this.f5988f = j9;
        }
        int i9 = 0;
        if (this.f5990h != j8) {
            y yVar = this.f5984b;
            j12 = -9223372036854775807L;
            long j18 = yVar.f6015n;
            if (j18 != -1) {
                yVar.f6017p = j18;
                yVar.f6018q = yVar.f6016o;
            }
            yVar.f6014m++;
            long j19 = j8 * 1000;
            e eVar = yVar.f6003a;
            j13 = -1;
            eVar.f5884a.b(j19);
            if (eVar.f5884a.a()) {
                eVar.f5886c = false;
            } else {
                if (eVar.f5887d != -9223372036854775807L) {
                    if (eVar.f5886c) {
                        d dVar = eVar.f5885b;
                        j14 = 0;
                        long j20 = dVar.f5879d;
                        if (j20 == 0 ? false : dVar.f5882g[(int) ((j20 - 1) % 15)]) {
                        }
                        eVar.f5886c = true;
                        eVar.f5885b.b(j19);
                    } else {
                        j14 = 0;
                    }
                    eVar.f5885b.c();
                    eVar.f5885b.b(eVar.f5887d);
                    eVar.f5886c = true;
                    eVar.f5885b.b(j19);
                }
                if (eVar.f5886c && eVar.f5885b.a()) {
                    d dVar2 = eVar.f5884a;
                    eVar.f5884a = eVar.f5885b;
                    eVar.f5885b = dVar2;
                    eVar.f5886c = false;
                }
                eVar.f5887d = j19;
                eVar.f5888e = !eVar.f5884a.a() ? 0 : eVar.f5888e + 1;
                yVar.c();
                this.f5990h = j8;
            }
            j14 = 0;
            if (eVar.f5886c) {
                d dVar22 = eVar.f5884a;
                eVar.f5884a = eVar.f5885b;
                eVar.f5885b = dVar22;
                eVar.f5886c = false;
            }
            eVar.f5887d = j19;
            eVar.f5888e = !eVar.f5884a.a() ? 0 : eVar.f5888e + 1;
            yVar.c();
            this.f5990h = j8;
        } else {
            j12 = -9223372036854775807L;
            j13 = -1;
            j14 = 0;
        }
        long jL = (long) ((j8 - j9) / ((double) this.f5992k));
        if (this.f5986d) {
            this.f5993l.getClass();
            jL -= x0.v.L(SystemClock.elapsedRealtime()) - j10;
        }
        long j21 = jL;
        uVar.f5981a = j21;
        if (!z8 || z9) {
            if (this.f5994m) {
                if (this.i == j12 || this.f5991j) {
                    int i10 = this.f5987e;
                    if (i10 != 0) {
                        if (i10 != 1) {
                            if (i10 != 2) {
                                if (i10 != 3) {
                                    throw new IllegalStateException();
                                }
                                this.f5993l.getClass();
                                long jL2 = x0.v.L(SystemClock.elapsedRealtime()) - this.f5989g;
                                if (!this.f5986d || j21 >= -30000 || jL2 <= 100000) {
                                    z10 = false;
                                }
                            } else if (j9 >= j11) {
                            }
                        }
                        z10 = true;
                    } else {
                        z10 = this.f5986d;
                    }
                }
                if (z10) {
                    return 0;
                }
                if (!this.f5986d || j9 == this.f5988f) {
                    return 5;
                }
                this.f5993l.getClass();
                long jNanoTime = System.nanoTime();
                y yVar2 = this.f5984b;
                long j22 = uVar.f5981a;
                Long.signum(j22);
                long j23 = (j22 * 1000) + jNanoTime;
                if (yVar2.f6017p == j13 || !yVar2.f6003a.f5884a.a()) {
                    i = 3;
                    j15 = -30000;
                    i5 = 2;
                    i8 = 1;
                } else {
                    e eVar2 = yVar2.f6003a;
                    if (eVar2.f5884a.a()) {
                        d dVar3 = eVar2.f5884a;
                        i = 3;
                        j15 = -30000;
                        long j24 = dVar3.f5880e;
                        j17 = j24 == j14 ? j14 : dVar3.f5881f / j24;
                    } else {
                        i = 3;
                        j15 = -30000;
                        j17 = j12;
                    }
                    i5 = 2;
                    i8 = 1;
                    long j25 = yVar2.f6018q + ((long) (((yVar2.f6014m - yVar2.f6017p) * j17) / yVar2.i));
                    if (Math.abs(j23 - j25) <= 20000000) {
                        j23 = j25;
                    } else {
                        yVar2.f6014m = j14;
                        long j26 = j13;
                        yVar2.f6017p = j26;
                        yVar2.f6015n = j26;
                    }
                }
                yVar2.f6015n = yVar2.f6014m;
                yVar2.f6016o = j23;
                x xVar = yVar2.f6005c;
                if (xVar != null && yVar2.f6012k != j12) {
                    long j27 = xVar.f5999q;
                    if (j27 != j12) {
                        long j28 = yVar2.f6012k;
                        long j29 = (((j23 - j27) / j28) * j28) + j27;
                        if (j23 <= j29) {
                            j16 = j29 - j28;
                        } else {
                            j16 = j29;
                            j29 = j28 + j29;
                        }
                        if (j29 - j23 >= j23 - j16) {
                            j29 = j16;
                        }
                        j23 = j29 - yVar2.f6013l;
                    }
                }
                uVar.f5982b = j23;
                long j30 = (j23 - jNanoTime) / 1000;
                uVar.f5981a = j30;
                boolean z11 = (this.i == j12 || this.f5991j) ? 0 : i8;
                if (this.f5983a.E0(j30, j9, z9, z11)) {
                    return 4;
                }
                long j31 = uVar.f5981a;
                if (j31 < j15 && !z9) {
                    i9 = i8;
                }
                if (i9 != 0) {
                    return z11 != 0 ? i : i5;
                }
                if (j31 > 50000) {
                    return 5;
                }
                return i8;
            }
            this.f5995n = true;
            if (this.f5983a.E0(j21, j9, z9, true)) {
                return 4;
            }
            if (!this.f5986d || uVar.f5981a >= 30000) {
                return 5;
            }
        }
        return 3;
    }

    public final boolean b(boolean z8) {
        if (z8 && (this.f5987e == 3 || (!this.f5994m && this.f5995n))) {
            this.i = -9223372036854775807L;
            return true;
        }
        if (this.i == -9223372036854775807L) {
            return false;
        }
        this.f5993l.getClass();
        if (SystemClock.elapsedRealtime() < this.i) {
            return true;
        }
        this.i = -9223372036854775807L;
        return false;
    }

    public final void c(boolean z8) {
        long jElapsedRealtime;
        this.f5991j = z8;
        long j8 = this.f5985c;
        if (j8 > 0) {
            this.f5993l.getClass();
            jElapsedRealtime = SystemClock.elapsedRealtime() + j8;
        } else {
            jElapsedRealtime = -9223372036854775807L;
        }
        this.i = jElapsedRealtime;
    }

    public final void d(int i) {
        this.f5987e = Math.min(this.f5987e, i);
    }

    public final void e() {
        this.f5986d = true;
        this.f5993l.getClass();
        this.f5989g = x0.v.L(SystemClock.elapsedRealtime());
        y yVar = this.f5984b;
        yVar.f6006d = true;
        yVar.f6014m = 0L;
        yVar.f6017p = -1L;
        yVar.f6015n = -1L;
        w wVar = yVar.f6004b;
        if (wVar != null) {
            x xVar = yVar.f6005c;
            xVar.getClass();
            xVar.f6000r.sendEmptyMessage(2);
            Handler handlerN = x0.v.n(null);
            DisplayManager displayManager = wVar.f5996a;
            displayManager.registerDisplayListener(wVar, handlerN);
            y.a(wVar.f5997b, displayManager.getDisplay(0));
        }
        yVar.d(false);
    }

    public final void f() {
        this.f5986d = false;
        this.i = -9223372036854775807L;
        y yVar = this.f5984b;
        yVar.f6006d = false;
        w wVar = yVar.f6004b;
        if (wVar != null) {
            wVar.f5996a.unregisterDisplayListener(wVar);
            x xVar = yVar.f6005c;
            xVar.getClass();
            xVar.f6000r.sendEmptyMessage(3);
        }
        yVar.b();
    }

    public final void g(float f3) {
        AbstractC1709a.d(f3 > 0.0f);
        if (f3 == this.f5992k) {
            return;
        }
        this.f5992k = f3;
        y yVar = this.f5984b;
        yVar.i = f3;
        yVar.f6014m = 0L;
        yVar.f6017p = -1L;
        yVar.f6015n = -1L;
        yVar.d(false);
    }
}
