package N;

import I.c;
import I.g;
import I.h;
import M.i;
import M.m;
import android.graphics.Bitmap;
import b0.AbstractC0399d;
import b0.D;
import b0.o;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final long[] f1449c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private List f1451e;

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

    public b(i iVar, long j2) {
        this.f1450d = iVar;
        this.f1447a = j2;
        this.f1451e = iVar.h();
        int size = iVar.h().size();
        this.f1452f = size;
        this.f1448b = new long[size * 2];
        int i2 = 0;
        for (m mVar : this.f1451e) {
            if (mVar.e() == 0) {
                this.f1448b[i2 * 2] = j2;
            } else {
                this.f1448b[i2 * 2] = (mVar.e() * 1000) / 90;
            }
            StringBuilder sb = new StringBuilder();
            sb.append("time ");
            sb.append(i2);
            sb.append(" start = ");
            int i3 = i2 * 2;
            sb.append(this.f1448b[i3]);
            o.d("PGSSubtitle", sb.toString(), 16);
            if (mVar.e() == 0) {
                this.f1448b[i3 + 1] = 1000000 + j2;
            } else {
                this.f1448b[i3 + 1] = (mVar.a() * 1000) / 90;
            }
            o.d("PGSSubtitle", "time " + i2 + " end = " + this.f1448b[i3 + 1], 16);
            i2++;
        }
        long[] jArr = this.f1448b;
        long[] jArrCopyOf = Arrays.copyOf(jArr, jArr.length);
        this.f1449c = jArrCopyOf;
        Arrays.sort(jArrCopyOf);
    }

    @Override // I.g
    public int a(long j2) {
        AbstractC0399d.a(j2 >= 0);
        int iB = D.b(this.f1449c, j2, false, false);
        if (iB < this.f1449c.length) {
            return iB;
        }
        return -1;
    }

    @Override // I.g
    public long b(int i2) {
        AbstractC0399d.a(i2 >= 0);
        AbstractC0399d.a(i2 < this.f1449c.length);
        return this.f1449c[i2];
    }

    @Override // I.g
    public List c(long j2) {
        o.d("PGSSubtitle", "getCues timeUs = " + j2, 16);
        ArrayList arrayList = null;
        for (int i2 = 0; i2 < this.f1452f; i2++) {
            long[] jArr = this.f1448b;
            int i3 = i2 * 2;
            if (jArr[i3] <= j2) {
                int i4 = i3 + 1;
                if (j2 < jArr[i4]) {
                    o.d("PGSSubtitle", "getCues " + i2 + "cueTimesUs[i * 2] = " + this.f1448b[i3] + " cueTimesUs[i * 2 + 1]) = " + this.f1448b[i4], 16);
                    if (arrayList == null) {
                        arrayList = new ArrayList();
                    }
                    try {
                        this.f1450d.a(i2);
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                    Bitmap bitmapC = this.f1450d.e().c();
                    h.a(bitmapC, j2, i2);
                    arrayList.add(new c(bitmapC));
                }
            }
        }
        return arrayList != null ? arrayList : Collections.emptyList();
    }

    @Override // I.g
    public int d() {
        return this.f1449c.length;
    }
}
