package defpackage;

import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.SystemClock;
import android.view.Choreographer;
import android.view.Surface;

/* JADX INFO: renamed from: ᵦˇʠ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C3560 {

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final C5221 f13631;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public boolean f13633;

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final long f13634;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public boolean f13635;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public boolean f13639;

    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    public final ᵦʝᵛᵤ f13640;

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public long f13641;

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public boolean f13643;

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public int f13636 = 0;

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public long f13645 = -9223372036854775807L;

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public long f13632 = -9223372036854775807L;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public long f13644 = -9223372036854775807L;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public float f13642 = 1.0f;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public C2353 f13638 = C2353.f9226;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public final boolean f13637 = true;

    public C3560(Context context, ᵦʝᵛᵤ r2, long j) {
        this.f13640 = r2;
        this.f13634 = j;
        this.f13631 = new C5221(context);
    }

    /* JADX INFO: renamed from: ʽˈˋ, reason: contains not printable characters */
    public final boolean m8071(boolean z) {
        if (z && (this.f13636 == 3 || (this.f13633 && (!this.f13635 || !this.f13637)))) {
            this.f13644 = -9223372036854775807L;
            return true;
        }
        if (this.f13644 == -9223372036854775807L) {
            return false;
        }
        this.f13638.getClass();
        if (SystemClock.elapsedRealtime() < this.f13644) {
            return true;
        }
        this.f13644 = -9223372036854775807L;
        return false;
    }

    /* JADX INFO: renamed from: ˊᵫᵗ, reason: contains not printable characters */
    public final void m8072(float f) {
        ᵻᵪ.ᵱᵽʡᵚ(f > 0.0f);
        if (f == this.f13642) {
            return;
        }
        this.f13642 = f;
        C5221 c5221 = this.f13631;
        c5221.f19679 = f;
        c5221.m10760(false);
    }

    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final void m8073(boolean z) {
        long jElapsedRealtime;
        this.f13639 = z;
        long j = this.f13634;
        if (j > 0) {
            this.f13638.getClass();
            jElapsedRealtime = SystemClock.elapsedRealtime() + j;
        } else {
            jElapsedRealtime = -9223372036854775807L;
        }
        this.f13644 = jElapsedRealtime;
    }

    /* JADX INFO: renamed from: ᵨᵣ, reason: contains not printable characters */
    public final void m8074(int i) {
        if (i == 0) {
            this.f13636 = 1;
        } else if (i == 1) {
            this.f13636 = 0;
        } else {
            if (i != 2) {
                ᵷᵝˎ.ᵱʡˏ();
                return;
            }
            this.f13636 = Math.min(this.f13636, 2);
        }
        this.f13631.m10757();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:119:0x0220  */
    /* JADX WARN: Removed duplicated region for block: B:152:0x02aa  */
    /* JADX WARN: Removed duplicated region for block: B:155:0x02b7 A[ORIG_RETURN, RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:157:0x02b9  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0082  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x0182 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:92:0x0183  */
    /* JADX INFO: renamed from: ᵲᵶᵳˈ, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int m8075(long j, long j2, long j3, long j4, boolean z, boolean z2, C3442 c3442) {
        long j5;
        long j6;
        long j7;
        int i;
        int i2;
        boolean z3;
        int i3;
        int i4;
        long j8;
        long j9;
        long j10;
        long j11;
        long j12;
        boolean z4;
        float f;
        float f2;
        long j13;
        c3442.f13274 = -9223372036854775807L;
        c3442.f13273 = -9223372036854775807L;
        if (this.f13643 && this.f13645 == -9223372036854775807L) {
            this.f13645 = j2;
        }
        if (this.f13632 != j) {
            C5221 c5221 = this.f13631;
            j5 = -9223372036854775807L;
            long j14 = c5221.f19666;
            if (j14 != -1) {
                c5221.f19673 = j14;
                c5221.f19664 = c5221.f19671;
                c5221.f19663 = c5221.f19669;
                c5221.f19677 = c5221.f19672;
            }
            c5221.f19668++;
            C1625 c1625 = c5221.f19675;
            j6 = 1000;
            long j15 = j * 1000;
            c1625.f6498.m5443(j15);
            if (c1625.f6498.m5445()) {
                c1625.f6496 = false;
                j7 = 0;
            } else {
                j7 = 0;
                if (c1625.f6499 != -9223372036854775807L) {
                    if (c1625.f6496) {
                        C2029 c2029 = c1625.f6495;
                        long j16 = c2029.f8066;
                        if (j16 == 0 ? false : c2029.f8065[(int) ((j16 - 1) % 15)]) {
                            c1625.f6495.m5444();
                            c1625.f6495.m5443(c1625.f6499);
                        }
                        c1625.f6496 = true;
                        c1625.f6495.m5443(j15);
                    }
                }
            }
            if (c1625.f6496 && c1625.f6495.m5445()) {
                C2029 c20292 = c1625.f6498;
                c1625.f6498 = c1625.f6495;
                c1625.f6495 = c20292;
                c1625.f6496 = false;
            }
            c1625.f6499 = j15;
            c1625.f6497 = c1625.f6498.m5445() ? 0 : c1625.f6497 + 1;
            c5221.m10758();
            this.f13632 = j;
        } else {
            j5 = -9223372036854775807L;
            j6 = 1000;
            j7 = 0;
        }
        long jM3214 = (long) ((j - j2) / ((double) this.f13642));
        if (this.f13643) {
            this.f13638.getClass();
            jM3214 -= AbstractC0956.m3214(SystemClock.elapsedRealtime()) - j3;
        }
        c3442.f13274 = jM3214;
        if (!z || z2) {
            if (this.f13635 || !this.f13637) {
                if (!this.f13637) {
                    this.f13633 = true;
                }
                if (this.f13644 == j5 || this.f13639) {
                    int i5 = this.f13636;
                    if (i5 != 0) {
                        if (i5 == 1) {
                            i = 3;
                            i2 = 5;
                        } else if (i5 == 2) {
                            i = 3;
                            i2 = 5;
                            if (j2 >= j4) {
                            }
                        } else {
                            if (i5 != 3) {
                                ᵷᵝˎ.ᵱʡˏ();
                                return 0;
                            }
                            this.f13638.getClass();
                            i = 3;
                            i2 = 5;
                            long jM32142 = AbstractC0956.m3214(SystemClock.elapsedRealtime()) - this.f13641;
                            if (this.f13643) {
                                long j17 = this.f13645;
                                if (j17 == j5 || j17 == j2 || jM3214 >= -30000 || jM32142 <= 100000) {
                                }
                            }
                        }
                        z3 = true;
                    } else {
                        i = 3;
                        i2 = 5;
                        z3 = this.f13643;
                    }
                    if (!z3) {
                        return 0;
                    }
                    if (this.f13643 && j2 != this.f13645) {
                        this.f13638.getClass();
                        long jNanoTime = System.nanoTime();
                        C5221 c52212 = this.f13631;
                        long j18 = (c3442.f13274 * j6) + jNanoTime;
                        if (c52212.f19673 != -1) {
                            if (c52212.f19675.f6498.m5445()) {
                                C1625 c16252 = c52212.f19675;
                                if (c16252.f6498.m5445()) {
                                    C2029 c20293 = c16252.f6498;
                                    i4 = 2;
                                    long j19 = c20293.f8063;
                                    i3 = 1;
                                    j13 = j19 == j7 ? j7 : c20293.f8067 / j19;
                                } else {
                                    i3 = 1;
                                    i4 = 2;
                                    j13 = j5;
                                }
                                j8 = -30000;
                                f = (c52212.f19668 - c52212.f19673) * j13;
                                f2 = c52212.f19679;
                            } else {
                                i3 = 1;
                                i4 = 2;
                                j8 = -30000;
                                f = (j - c52212.f19663) * j6;
                                f2 = c52212.f19679;
                            }
                            long j20 = c52212.f19664 + ((long) (f / f2));
                            if (Math.abs(j18 - j20) <= 20000000) {
                                j18 = j20;
                            } else {
                                c52212.m10757();
                            }
                        } else {
                            i3 = 1;
                            i4 = 2;
                            j8 = -30000;
                        }
                        c52212.f19666 = c52212.f19668;
                        c52212.f19671 = j18;
                        c52212.f19669 = j;
                        AbstractC1358 abstractC1358 = c52212.f19667;
                        if (abstractC1358 == null) {
                            j11 = jNanoTime;
                            c3442.f13273 = j18;
                            j12 = (j18 - j11) / j6;
                            c3442.f13274 = j12;
                            z4 = (this.f13644 != j5 || this.f13639) ? 0 : i3;
                            if (!this.f13640.ᵱʢᵢ(j12, j2, z2, z4)) {
                                return 4;
                            }
                            long j21 = c3442.f13274;
                            if (j21 < j8 && !z2) {
                                return z4 != 0 ? i : i4;
                            }
                            if (j21 <= 50000) {
                                return i3;
                            }
                        } else {
                            long j22 = abstractC1358.f5628;
                            long j23 = c52212.f19667.f5630;
                            if (j22 != j5 && j23 != j5) {
                                long j24 = (((j18 - j22) / j23) * j23) + j22;
                                if (j18 <= j24) {
                                    j9 = j24 - j23;
                                } else {
                                    j24 += j23;
                                    j9 = j24;
                                }
                                long j25 = j24 - j18;
                                long j26 = j18 - j9;
                                long jAbs = Math.abs(j25 - j26);
                                if (jAbs < j23 / 2) {
                                    j10 = j9;
                                    long j27 = j23 / 4;
                                    if (jAbs < j27) {
                                        j11 = jNanoTime;
                                        long j28 = c52212.f19677;
                                        if (j28 != j7) {
                                            c52212.f19672 = j28;
                                        } else {
                                            if (j25 < j26) {
                                                j27 = -j27;
                                            }
                                            c52212.f19672 = j27;
                                        }
                                    } else {
                                        j11 = jNanoTime;
                                        c52212.f19672 = j7;
                                    }
                                } else {
                                    j10 = j9;
                                    j11 = jNanoTime;
                                    c52212.f19672 = c52212.f19677;
                                }
                                if (j25 + c52212.f19672 >= j26) {
                                    j24 = j10;
                                }
                                j18 = j24 - ((j23 * 80) / 100);
                            }
                            c3442.f13273 = j18;
                            j12 = (j18 - j11) / j6;
                            c3442.f13274 = j12;
                            if (this.f13644 != j5) {
                                if (!this.f13640.ᵱʢᵢ(j12, j2, z2, z4)) {
                                }
                            }
                        }
                    }
                    return i2;
                }
                i = 3;
                i2 = 5;
                z3 = false;
                if (!z3) {
                }
            } else {
                if (this.f13640.ᵱʢᵢ(jM3214, j2, z2, true)) {
                    return 4;
                }
                if (!this.f13643 || c3442.f13274 >= 30000) {
                    this.f13633 = true;
                    return 5;
                }
            }
        }
        return 3;
    }

    /* JADX INFO: renamed from: ᵵᵽ, reason: contains not printable characters */
    public final void m8076(Surface surface) {
        this.f13635 = surface != null;
        this.f13633 = false;
        C5221 c5221 = this.f13631;
        if (c5221.f19670 != surface) {
            c5221.m10759();
            c5221.f19670 = surface;
            c5221.m10760(true);
        }
        this.f13636 = Math.min(this.f13636, 1);
    }

    /* JADX INFO: renamed from: ᵷᵺʾᵖ, reason: contains not printable characters */
    public final void m8077() {
        this.f13643 = true;
        this.f13638.getClass();
        this.f13641 = AbstractC0956.m3214(SystemClock.elapsedRealtime());
        C5221 c5221 = this.f13631;
        c5221.f19678 = true;
        c5221.m10757();
        DisplayManager displayManager = (DisplayManager) c5221.f19662.getSystemService("display");
        AbstractC1358 choreographerVsyncCallbackC2344 = null;
        if (displayManager != null) {
            try {
                Choreographer choreographer = Choreographer.getInstance();
                choreographerVsyncCallbackC2344 = Build.VERSION.SDK_INT >= 33 ? new ChoreographerVsyncCallbackC2344(choreographer, displayManager) : new ChoreographerFrameCallbackC0904(choreographer, displayManager);
            } catch (RuntimeException e) {
                ˋˀᵧ.ᵠˏˏ("Vsync sampling disabled due to platform error", e);
            }
        }
        c5221.f19667 = choreographerVsyncCallbackC2344;
        if (choreographerVsyncCallbackC2344 != null) {
            choreographerVsyncCallbackC2344.mo3149();
        }
        c5221.m10760(false);
    }

    /* JADX INFO: renamed from: ᵻˈᵦʼ, reason: contains not printable characters */
    public final void m8078(float f) {
        C5221 c5221 = this.f13631;
        c5221.f19680 = f;
        C1625 c1625 = c5221.f19675;
        c1625.f6498.m5444();
        c1625.f6495.m5444();
        c1625.f6496 = false;
        c1625.f6499 = -9223372036854775807L;
        c1625.f6497 = 0;
        c5221.m10758();
    }
}
