package k2;

import androidx.annotation.Nullable;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.q0;
import androidx.media3.extractor.s0;
import androidx.media3.extractor.u0;

/* JADX INFO: loaded from: classes.dex */
public final class i implements f {

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

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

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

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

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

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

    @Nullable
    private final long[] tableOfContents;

    private i(long j10, int i10, long j11, int i11, long j12, @Nullable long[] jArr) {
        this.f29056a = j10;
        this.f29057b = i10;
        this.f29058c = j11;
        this.f29059d = i11;
        this.f29060e = j12;
        this.tableOfContents = jArr;
        this.f29061f = j12 != -1 ? j10 + j12 : -1L;
    }

    @Nullable
    public static i create(h hVar, long j10) {
        long jA = hVar.a();
        if (jA == -9223372036854775807L) {
            return null;
        }
        q0 q0Var = hVar.f29051a;
        return new i(j10, q0Var.f3451b, jA, q0Var.f3454e, hVar.f29053c, hVar.tableOfContents);
    }

    @Override // k2.f
    public final long a() {
        return this.f29061f;
    }

    @Override // k2.f
    public final long b() {
        return this.f29056a + ((long) this.f29057b);
    }

    @Override // k2.f
    public final int c() {
        return this.f29059d;
    }

    @Override // androidx.media3.extractor.t0
    public final long getDurationUs() {
        return this.f29058c;
    }

    @Override // androidx.media3.extractor.t0
    public final s0 getSeekPoints(long j10) {
        double d10;
        boolean zIsSeekable = isSeekable();
        int i10 = this.f29057b;
        long j11 = this.f29056a;
        if (!zIsSeekable) {
            u0 u0Var = new u0(0L, j11 + ((long) i10));
            return new s0(u0Var, u0Var);
        }
        long jConstrainValue = Util.constrainValue(j10, 0L, this.f29058c);
        double d11 = (jConstrainValue * 100.0d) / this.f29058c;
        double d12 = 0.0d;
        if (d11 <= 0.0d) {
            d10 = 256.0d;
        } else if (d11 >= 100.0d) {
            d10 = 256.0d;
            d12 = 256.0d;
        } else {
            int i11 = (int) d11;
            double d13 = ((long[]) Assertions.checkStateNotNull(this.tableOfContents))[i11];
            d12 = (((i11 == 99 ? 256.0d : r9[i11 + 1]) - d13) * (d11 - ((double) i11))) + d13;
            d10 = 256.0d;
        }
        double d14 = d12 / d10;
        long j12 = this.f29060e;
        u0 u0Var2 = new u0(jConstrainValue, j11 + Util.constrainValue(Math.round(d14 * j12), i10, j12 - 1));
        return new s0(u0Var2, u0Var2);
    }

    @Override // k2.f
    public final long getTimeUs(long j10) {
        long j11 = j10 - this.f29056a;
        if (!isSeekable() || j11 <= this.f29057b) {
            return 0L;
        }
        long[] jArr = (long[]) Assertions.checkStateNotNull(this.tableOfContents);
        double d10 = (j11 * 256.0d) / this.f29060e;
        int iBinarySearchFloor = Util.binarySearchFloor(jArr, (long) d10, true, true);
        long j12 = this.f29058c;
        long j13 = (((long) iBinarySearchFloor) * j12) / 100;
        long j14 = jArr[iBinarySearchFloor];
        int i10 = iBinarySearchFloor + 1;
        long j15 = (j12 * ((long) i10)) / 100;
        return Math.round((j14 == (iBinarySearchFloor == 99 ? 256L : jArr[i10]) ? 0.0d : (d10 - j14) / (r0 - j14)) * (j15 - j13)) + j13;
    }

    @Override // androidx.media3.extractor.t0
    public final boolean isSeekable() {
        return this.tableOfContents != null;
    }
}
