package n2;

import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.j1;
import com.google.common.collect.z0;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class c implements g {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final j1 f30763c = j1.c().d(new androidx.media3.common.b(21));

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final long[] f30765b;

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:30:0x00b8  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public c(List list) {
        long j10 = -9223372036854775807L;
        int i10 = 0;
        if (list.size() == 1) {
            b bVar = (b) z0.p(list);
            long j11 = bVar.f30760b;
            long j12 = j11 == -9223372036854775807L ? 0L : j11;
            long j13 = bVar.f30761c;
            ImmutableList immutableList = bVar.f30759a;
            if (j13 == -9223372036854775807L) {
                this.f30764a = ImmutableList.w(immutableList);
                this.f30765b = new long[]{j12};
                return;
            } else {
                this.f30764a = ImmutableList.x(immutableList, ImmutableList.t());
                this.f30765b = new long[]{j12, j12 + j13};
                return;
            }
        }
        long[] jArr = new long[list.size() * 2];
        this.f30765b = jArr;
        Arrays.fill(jArr, Long.MAX_VALUE);
        ArrayList arrayList = new ArrayList();
        ImmutableList immutableListY = ImmutableList.y(f30763c, list);
        int i11 = 0;
        while (i10 < immutableListY.size()) {
            b bVar2 = (b) immutableListY.get(i10);
            long j14 = bVar2.f30760b;
            j14 = j14 == j10 ? 0L : j14;
            long j15 = bVar2.f30761c;
            long j16 = j14 + j15;
            ImmutableList immutableList2 = bVar2.f30759a;
            if (i11 != 0) {
                int i12 = i11 - 1;
                long j17 = this.f30765b[i12];
                if (j17 < j14) {
                    this.f30765b[i11] = j14;
                    arrayList.add(immutableList2);
                    i11++;
                } else if (j17 == j14 && ((ImmutableList) arrayList.get(i12)).isEmpty()) {
                    arrayList.set(i12, immutableList2);
                } else {
                    Log.w("CuesWithTimingSubtitle", "Truncating unsupported overlapping cues.");
                    this.f30765b[i12] = j14;
                    arrayList.set(i12, immutableList2);
                }
            }
            if (j15 != -9223372036854775807L) {
                this.f30765b[i11] = j16;
                arrayList.add(ImmutableList.t());
                i11++;
            }
            i10++;
            j10 = -9223372036854775807L;
        }
        this.f30764a = ImmutableList.p(arrayList);
    }

    @Override // n2.g
    public final int a(long j10) {
        int iBinarySearchCeil = Util.binarySearchCeil(this.f30765b, j10, false, false);
        if (iBinarySearchCeil < this.f30764a.size()) {
            return iBinarySearchCeil;
        }
        return -1;
    }

    @Override // n2.g
    public final long b(int i10) {
        Assertions.checkArgument(i10 < this.f30764a.size());
        return this.f30765b[i10];
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // n2.g
    public final List c(long j10) {
        int iBinarySearchFloor = Util.binarySearchFloor(this.f30765b, j10, true, false);
        return iBinarySearchFloor == -1 ? ImmutableList.t() : (ImmutableList) this.f30764a.get(iBinarySearchFloor);
    }

    @Override // n2.g
    public final int d() {
        return this.f30764a.size();
    }
}
