package n;

import a0.InterfaceC0147b;
import android.os.Handler;
import com.mstar.android.tvapi.impl.PlayerImpl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/* JADX INFO: renamed from: n.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0641g implements n {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final InterfaceC0147b f5523a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final List f5524b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final HashMap f5525c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final Handler f5526d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final long f5527e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final long f5528f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final float f5529g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final float f5530h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private int f5531i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private int f5533k;

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

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

    /* JADX INFO: renamed from: n.g$a */
    public interface a {
    }

    /* JADX INFO: renamed from: n.g$b */
    private static class b {

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

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public long f5539d = -1;

        public b(int i2) {
            this.f5536a = i2;
        }
    }

    public C0641g(InterfaceC0147b interfaceC0147b) {
        this(interfaceC0147b, null, null);
    }

    private int f(int i2) {
        float f2 = i2 / this.f5531i;
        if (f2 > this.f5530h) {
            return 0;
        }
        return f2 < this.f5529g ? 2 : 1;
    }

    private int g(long j2, long j3) {
        if (j3 == -1) {
            return 0;
        }
        long j4 = j3 - j2;
        if (j4 > this.f5528f) {
            return 0;
        }
        return j4 < this.f5527e ? 2 : 1;
    }

    private void h(boolean z2) {
    }

    private void i() {
        int iMax = this.f5533k;
        int i2 = 0;
        boolean z2 = false;
        boolean z3 = false;
        while (true) {
            boolean z4 = true;
            if (i2 >= this.f5524b.size()) {
                break;
            }
            b bVar = (b) this.f5525c.get(this.f5524b.get(i2));
            z2 |= bVar.f5538c;
            if (bVar.f5539d == -1) {
                z4 = false;
            }
            z3 |= z4;
            iMax = Math.max(iMax, bVar.f5537b);
            i2++;
        }
        boolean z5 = !this.f5524b.isEmpty() && (z2 || z3) && (iMax == 2 || (iMax == 1 && this.f5534l));
        this.f5534l = z5;
        if (z5 && !this.f5535m) {
            a0.t.f2022d.a(0);
            this.f5535m = true;
            h(true);
        } else if (!z5 && this.f5535m && !z2) {
            a0.t.f2022d.b(0);
            this.f5535m = false;
            h(false);
        }
        this.f5532j = -1L;
        if (this.f5534l) {
            for (int i3 = 0; i3 < this.f5524b.size(); i3++) {
                long j2 = ((b) this.f5525c.get(this.f5524b.get(i3))).f5539d;
                if (j2 != -1) {
                    long j3 = this.f5532j;
                    if (j3 == -1 || j2 < j3) {
                        this.f5532j = j2;
                    }
                }
            }
        }
    }

    @Override // n.n
    public void a(Object obj, int i2) {
        this.f5524b.add(obj);
        this.f5525c.put(obj, new b(i2));
        this.f5531i += i2;
    }

    @Override // n.n
    public void b() {
        this.f5523a.f(this.f5531i);
    }

    @Override // n.n
    public boolean c(Object obj, long j2, long j3, boolean z2) {
        int iG = g(j2, j3);
        b bVar = (b) this.f5525c.get(obj);
        boolean z3 = (bVar.f5537b == iG && bVar.f5539d == j3 && bVar.f5538c == z2) ? false : true;
        if (z3) {
            bVar.f5537b = iG;
            bVar.f5539d = j3;
            bVar.f5538c = z2;
        }
        int iD = this.f5523a.d();
        int iF = f(iD);
        boolean z4 = this.f5533k != iF;
        if (z4) {
            this.f5533k = iF;
        }
        if (z3 || z4) {
            i();
        }
        return (iD < this.f5531i || iG == 2) && j3 != -1 && j3 <= this.f5532j;
    }

    @Override // n.n
    public void d(Object obj) {
        this.f5524b.remove(obj);
        this.f5531i -= ((b) this.f5525c.remove(obj)).f5536a;
        i();
    }

    @Override // n.n
    public InterfaceC0147b e() {
        return this.f5523a;
    }

    public C0641g(InterfaceC0147b interfaceC0147b, Handler handler, a aVar) {
        this(interfaceC0147b, handler, aVar, PlayerImpl.TVPLAYER_PVR_EVENT_START, 30000, 0.2f, 0.8f);
    }

    public C0641g(InterfaceC0147b interfaceC0147b, Handler handler, a aVar, int i2, int i3, float f2, float f3) {
        this.f5523a = interfaceC0147b;
        this.f5526d = handler;
        this.f5524b = new ArrayList();
        this.f5525c = new HashMap();
        this.f5527e = ((long) i2) * 1000;
        this.f5528f = ((long) i3) * 1000;
        this.f5529g = f2;
        this.f5530h = f3;
    }
}
