package L0;

import B0.r0;
import android.net.Uri;
import e0.C0853a;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import u0.C1579o;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class j0 implements A, P0.h {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final boolean f3847A;

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

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public byte[] f3849C;
    public int D;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public final z0.k f3850q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final C0853a f3851r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final z0.y f3852s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final C4.f f3853t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final E0.e f3854u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final n0 f3855v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final ArrayList f3856w = new ArrayList();

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

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final P0.m f3858y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C1579o f3859z;

    public j0(z0.k kVar, C0853a c0853a, z0.y yVar, C1579o c1579o, long j8, C4.f fVar, E0.e eVar, boolean z8, Q0.a aVar) {
        this.f3850q = kVar;
        this.f3851r = c0853a;
        this.f3852s = yVar;
        this.f3859z = c1579o;
        this.f3857x = j8;
        this.f3853t = fVar;
        this.f3854u = eVar;
        this.f3847A = z8;
        this.f3855v = new n0(new u0.T("", c1579o));
        this.f3858y = aVar != null ? new P0.m(aVar) : new P0.m("SingleSampleMediaPeriod");
    }

    @Override // L0.e0
    public final boolean a() {
        return this.f3858y.b();
    }

    @Override // L0.A
    public final long b(O0.s[] sVarArr, boolean[] zArr, c0[] c0VarArr, boolean[] zArr2, long j8) {
        for (int i = 0; i < sVarArr.length; i++) {
            c0 c0Var = c0VarArr[i];
            ArrayList arrayList = this.f3856w;
            if (c0Var != null && (sVarArr[i] == null || !zArr[i])) {
                arrayList.remove(c0Var);
                c0VarArr[i] = null;
            }
            if (c0VarArr[i] == null && sVarArr[i] != null) {
                h0 h0Var = new h0(this);
                arrayList.add(h0Var);
                c0VarArr[i] = h0Var;
                zArr2[i] = true;
            }
        }
        return j8;
    }

    @Override // L0.A
    public final n0 d() {
        return this.f3855v;
    }

    @Override // P0.h
    public final void e(P0.j jVar, long j8, long j9, int i) {
        C0164t c0164t;
        i0 i0Var = (i0) jVar;
        z0.x xVar = i0Var.f3841b;
        if (i == 0) {
            c0164t = new C0164t(i0Var.f3840a);
        } else {
            Uri uri = xVar.f19183s;
            c0164t = new C0164t(j9);
        }
        this.f3854u.e(c0164t, 1, -1, this.f3859z, 0, null, 0L, this.f3857x, i);
    }

    @Override // L0.e0
    public final boolean f(B0.T t6) {
        if (this.f3848B) {
            return false;
        }
        P0.m mVar = this.f3858y;
        if (mVar.b() || mVar.f5306c != null) {
            return false;
        }
        z0.h hVarC = this.f3851r.c();
        z0.y yVar = this.f3852s;
        if (yVar != null) {
            ((z0.l) hVarC).k(yVar);
        }
        i0 i0Var = new i0(hVarC, this.f3850q);
        this.f3853t.getClass();
        mVar.d(i0Var, this, 3);
        return true;
    }

    @Override // P0.h
    public final void g(P0.j jVar, long j8, long j9) {
        i0 i0Var = (i0) jVar;
        this.D = (int) i0Var.f3841b.f19182r;
        byte[] bArr = i0Var.f3842c;
        bArr.getClass();
        this.f3849C = bArr;
        this.f3848B = true;
        Uri uri = i0Var.f3841b.f19183s;
        C0164t c0164t = new C0164t(j9);
        this.f3853t.getClass();
        this.f3854u.c(c0164t, 1, -1, this.f3859z, 0, null, 0L, this.f3857x);
    }

    @Override // L0.e0
    public final long k() {
        return this.f3848B ? Long.MIN_VALUE : 0L;
    }

    @Override // P0.h
    public final B1.f n(P0.j jVar, long j8, long j9, IOException iOException, int i) {
        long jMin;
        B1.f fVar;
        Uri uri = ((i0) jVar).f3841b.f19183s;
        C0164t c0164t = new C0164t(j9);
        int i5 = x0.v.f18553a;
        this.f3853t.getClass();
        if ((iOException instanceof u0.F) || (iOException instanceof FileNotFoundException) || (iOException instanceof z0.q) || (iOException instanceof P0.l)) {
            jMin = -9223372036854775807L;
            break;
        }
        int i8 = z0.i.f19130r;
        for (Throwable cause = iOException; cause != null; cause = cause.getCause()) {
            if ((cause instanceof z0.i) && ((z0.i) cause).f19131q == 2008) {
                jMin = -9223372036854775807L;
                break;
            }
        }
        jMin = Math.min((i - 1) * 1000, 5000);
        boolean z8 = jMin == -9223372036854775807L || i >= 3;
        if (this.f3847A && z8) {
            AbstractC1709a.C("SingleSampleMediaPeriod", "Loading failed, treating as end-of-stream.", iOException);
            this.f3848B = true;
            fVar = P0.m.f5302e;
        } else {
            fVar = jMin != -9223372036854775807L ? new B1.f(0, jMin, false) : P0.m.f5303f;
        }
        int i9 = fVar.f961a;
        this.f3854u.d(c0164t, 1, -1, this.f3859z, 0, null, 0L, this.f3857x, iOException, !(i9 == 0 || i9 == 1));
        return fVar;
    }

    @Override // L0.A
    public final void o(InterfaceC0170z interfaceC0170z, long j8) {
        interfaceC0170z.n(this);
    }

    @Override // L0.A
    public final long p(long j8) {
        int i = 0;
        while (true) {
            ArrayList arrayList = this.f3856w;
            if (i >= arrayList.size()) {
                return j8;
            }
            h0 h0Var = (h0) arrayList.get(i);
            if (h0Var.f3835q == 2) {
                h0Var.f3835q = 1;
            }
            i++;
        }
    }

    @Override // L0.e0
    public final long r() {
        return (this.f3848B || this.f3858y.b()) ? Long.MIN_VALUE : 0L;
    }

    @Override // P0.h
    public final void s(P0.j jVar, long j8, long j9, boolean z8) {
        Uri uri = ((i0) jVar).f3841b.f19183s;
        C0164t c0164t = new C0164t(j9);
        this.f3853t.getClass();
        this.f3854u.b(c0164t, 1, -1, null, 0, null, 0L, this.f3857x);
    }

    @Override // L0.A
    public final long t() {
        return -9223372036854775807L;
    }

    @Override // L0.A
    public final void l() {
    }

    @Override // L0.A
    public final void q(long j8) {
    }

    @Override // L0.e0
    public final void u(long j8) {
    }

    @Override // L0.A
    public final long c(long j8, r0 r0Var) {
        return j8;
    }
}
