package R0;

import android.content.Context;
import android.hardware.display.DisplayManager;
import android.view.Display;
import android.view.Surface;
import x0.AbstractC1709a;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public float f6010h;
    public float i;

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

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

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

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

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

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

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

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

    public y(Context context) {
        DisplayManager displayManager;
        e eVar = new e();
        eVar.f5884a = new d();
        eVar.f5885b = new d();
        eVar.f5887d = -9223372036854775807L;
        this.f6003a = eVar;
        w wVar = (context == null || (displayManager = (DisplayManager) context.getSystemService("display")) == null) ? null : new w(this, displayManager);
        this.f6004b = wVar;
        this.f6005c = wVar != null ? x.f5998u : null;
        this.f6012k = -9223372036854775807L;
        this.f6013l = -9223372036854775807L;
        this.f6008f = -1.0f;
        this.i = 1.0f;
        this.f6011j = 0;
    }

    public static void a(y yVar, Display display) {
        yVar.getClass();
        if (display != null) {
            long refreshRate = (long) (1.0E9d / ((double) display.getRefreshRate()));
            yVar.f6012k = refreshRate;
            yVar.f6013l = (refreshRate * 80) / 100;
        } else {
            AbstractC1709a.B("VideoFrameReleaseHelper", "Unable to query display refresh rate");
            yVar.f6012k = -9223372036854775807L;
            yVar.f6013l = -9223372036854775807L;
        }
    }

    public final void b() {
        Surface surface;
        if (x0.v.f18553a < 30 || (surface = this.f6007e) == null || this.f6011j == Integer.MIN_VALUE || this.f6010h == 0.0f) {
            return;
        }
        this.f6010h = 0.0f;
        try {
            surface.setFrameRate(0.0f, 0);
        } catch (IllegalStateException e8) {
            AbstractC1709a.p("VideoFrameReleaseHelper", "Failed to call Surface.setFrameRate", e8);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:45:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void c() {
        float f3;
        float f7;
        if (x0.v.f18553a < 30 || this.f6007e == null) {
            return;
        }
        e eVar = this.f6003a;
        if (!eVar.f5884a.a()) {
            f3 = this.f6008f;
        } else if (eVar.f5884a.a()) {
            f3 = (float) (1.0E9d / (eVar.f5884a.f5880e != 0 ? r2.f5881f / r4 : 0L));
        } else {
            f3 = -1.0f;
        }
        float f8 = this.f6009g;
        if (f3 == f8) {
            return;
        }
        if (f3 == -1.0f || f8 == -1.0f) {
            if (f3 == -1.0f && eVar.f5888e < 30) {
                return;
            }
        } else if (eVar.f5884a.a()) {
            if ((eVar.f5884a.a() ? eVar.f5884a.f5881f : -9223372036854775807L) >= 5000000000L) {
                f7 = 0.02f;
            }
            if (Math.abs(f3 - this.f6009g) < f7) {
            }
        } else {
            f7 = 1.0f;
            if (Math.abs(f3 - this.f6009g) < f7) {
                return;
            }
        }
        this.f6009g = f3;
        d(false);
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x0022  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(boolean z8) {
        Surface surface;
        float f3;
        if (x0.v.f18553a < 30 || (surface = this.f6007e) == null || this.f6011j == Integer.MIN_VALUE) {
            return;
        }
        if (this.f6006d) {
            float f7 = this.f6009g;
            f3 = f7 != -1.0f ? f7 * this.i : 0.0f;
        }
        if (z8 || this.f6010h != f3) {
            this.f6010h = f3;
            try {
                surface.setFrameRate(f3, f3 == 0.0f ? 0 : 1);
            } catch (IllegalStateException e8) {
                AbstractC1709a.p("VideoFrameReleaseHelper", "Failed to call Surface.setFrameRate", e8);
            }
        }
    }
}
