package L0;

import B0.t0;
import android.net.Uri;
import g1.C0971b;
import java.io.InterruptedIOException;
import java.util.Collections;
import java.util.Map;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class P implements P0.j {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final z0.x f3672b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final A1.y f3673c;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public volatile boolean f3677g;
    public long i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public z0.k f3679j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public T0.F f3680k;

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final /* synthetic */ T f3682m;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final L4.h f3676f = new L4.h();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f3678h = true;

    public P(T t6, Uri uri, z0.h hVar, A1.y yVar, T t8, t0 t0Var) {
        this.f3682m = t6;
        this.f3671a = uri;
        this.f3672b = new z0.x(hVar);
        this.f3673c = yVar;
        this.f3674d = t8;
        this.f3675e = t0Var;
        C0164t.f3906b.getAndIncrement();
        this.f3679j = c(0L);
    }

    @Override // P0.j
    public final void a() {
        z0.h c0163s;
        T0.m mVar;
        int i;
        int iE = 0;
        while (iE == 0 && !this.f3677g) {
            try {
                long j8 = this.f3676f.f4006a;
                z0.k kVarC = c(j8);
                this.f3679j = kVarC;
                long jG = this.f3672b.g(kVarC);
                if (this.f3677g) {
                    if (iE != 1 && this.f3673c.r() != -1) {
                        this.f3676f.f4006a = this.f3673c.r();
                    }
                    W3.b.k(this.f3672b);
                    return;
                }
                if (jG != -1) {
                    jG += j8;
                    T t6 = this.f3682m;
                    t6.f3694G.post(new N(t6, 0));
                }
                long j9 = jG;
                this.f3682m.f3695I = C0971b.d(this.f3672b.f19181q.m());
                z0.x xVar = this.f3672b;
                C0971b c0971b = this.f3682m.f3695I;
                if (c0971b == null || (i = c0971b.f12882f) == -1) {
                    c0163s = xVar;
                } else {
                    c0163s = new C0163s(xVar, i, this);
                    T t8 = this.f3682m;
                    t8.getClass();
                    T0.F fD = t8.D(new S(0, true));
                    this.f3680k = fD;
                    fD.e(T.f3688g0);
                }
                this.f3673c.v(c0163s, this.f3671a, this.f3672b.f19181q.m(), j8, j9, this.f3674d);
                if (this.f3682m.f3695I != null && (mVar = (T0.m) this.f3673c.f364s) != null) {
                    T0.m mVarC = mVar.c();
                    if (mVarC instanceof m1.d) {
                        ((m1.d) mVarC).f14576r = true;
                    }
                }
                if (this.f3678h) {
                    A1.y yVar = this.f3673c;
                    long j10 = this.i;
                    T0.m mVar2 = (T0.m) yVar.f364s;
                    mVar2.getClass();
                    mVar2.i(j8, j10);
                    this.f3678h = false;
                }
                while (iE == 0 && !this.f3677g) {
                    try {
                        t0 t0Var = this.f3675e;
                        synchronized (t0Var) {
                            while (!t0Var.f916b) {
                                t0Var.wait();
                            }
                        }
                        A1.y yVar2 = this.f3673c;
                        L4.h hVar = this.f3676f;
                        T0.m mVar3 = (T0.m) yVar2.f364s;
                        mVar3.getClass();
                        T0.j jVar = (T0.j) yVar2.f365t;
                        jVar.getClass();
                        iE = mVar3.e(jVar, hVar);
                        long jR = this.f3673c.r();
                        if (jR > this.f3682m.f3725y + j8) {
                            this.f3675e.e();
                            T t9 = this.f3682m;
                            t9.f3694G.post(t9.f3693F);
                            j8 = jR;
                        }
                    } catch (InterruptedException unused) {
                        throw new InterruptedIOException();
                    }
                }
                if (iE == 1) {
                    iE = 0;
                } else if (this.f3673c.r() != -1) {
                    this.f3676f.f4006a = this.f3673c.r();
                }
                W3.b.k(this.f3672b);
            } catch (Throwable th) {
                if (iE != 1 && this.f3673c.r() != -1) {
                    this.f3676f.f4006a = this.f3673c.r();
                }
                W3.b.k(this.f3672b);
                throw th;
            }
        }
    }

    @Override // P0.j
    public final void b() {
        this.f3677g = true;
    }

    public final z0.k c(long j8) {
        Map map = Collections.EMPTY_MAP;
        this.f3682m.getClass();
        Map map2 = T.f3687f0;
        Uri uri = this.f3671a;
        AbstractC1709a.l(uri, "The uri must be set.");
        return new z0.k(uri, 1, null, map2, j8, -1L, 6);
    }
}
