package b0;

import a0.r;
import a0.y;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
import java.io.IOException;
import java.util.concurrent.CancellationException;

/* JADX INFO: loaded from: classes.dex */
public class j implements r.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final y.a f2996a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final a0.x f2997b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final Handler f2998c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    volatile String f2999d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private a0.r f3001f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private a0.y f3002g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private long f3003h;

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private long f3005j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private c f3006k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private volatile Object f3007l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private volatile long f3008m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private volatile long f3009n;

    public interface a {
    }

    public interface b {
        void c(IOException iOException);

        void d(Object obj);
    }

    public static final class c extends IOException {
        public c(Throwable th) {
            super(th);
        }
    }

    public interface d {
        String a();
    }

    private class e implements r.a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final a0.y f3010a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private final Looper f3011b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private final b f3012c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private final a0.r f3013d = new a0.r("manifestLoader:single");

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

        public e(a0.y yVar, Looper looper, b bVar) {
            this.f3010a = yVar;
            this.f3011b = looper;
            this.f3012c = bVar;
        }

        private void a() {
            this.f3013d.e();
        }

        public void b() {
            this.f3014e = SystemClock.elapsedRealtime();
            this.f3013d.h(this.f3011b, this.f3010a, this);
        }

        @Override // a0.r.a
        public void l(r.c cVar) {
            try {
                Object objA = this.f3010a.a();
                j.this.k(objA, this.f3014e);
                this.f3012c.d(objA);
            } finally {
                a();
            }
        }

        @Override // a0.r.a
        public void n(r.c cVar, IOException iOException) {
            try {
                this.f3012c.c(iOException);
            } finally {
                a();
            }
        }

        @Override // a0.r.a
        public void v(r.c cVar) {
            try {
                this.f3012c.c(new c(new CancellationException()));
            } finally {
                a();
            }
        }
    }

    public j(String str, a0.x xVar, y.a aVar) {
        this(str, xVar, aVar, null, null);
    }

    private long f(long j2) {
        return Math.min((j2 - 1) * 1000, 5000L);
    }

    private void h(IOException iOException) {
    }

    private void i() {
    }

    private void j() {
    }

    public void a() {
        a0.r rVar;
        int i2 = this.f3000e - 1;
        this.f3000e = i2;
        if (i2 != 0 || (rVar = this.f3001f) == null) {
            return;
        }
        rVar.e();
        this.f3001f = null;
    }

    public void b() {
        int i2 = this.f3000e;
        this.f3000e = i2 + 1;
        if (i2 == 0) {
            this.f3004i = 0;
            this.f3006k = null;
        }
    }

    public Object c() {
        return this.f3007l;
    }

    public long d() {
        return this.f3009n;
    }

    public long e() {
        return this.f3008m;
    }

    public void g() throws c {
        c cVar = this.f3006k;
        if (cVar != null && this.f3004i > 1) {
            throw cVar;
        }
    }

    void k(Object obj, long j2) {
        this.f3007l = obj;
        this.f3008m = j2;
        this.f3009n = SystemClock.elapsedRealtime();
    }

    @Override // a0.r.a
    public void l(r.c cVar) {
        a0.y yVar = this.f3002g;
        if (yVar != cVar) {
            return;
        }
        this.f3007l = yVar.a();
        this.f3008m = this.f3003h;
        this.f3009n = SystemClock.elapsedRealtime();
        this.f3004i = 0;
        this.f3006k = null;
        if (this.f3007l instanceof d) {
            String strA = ((d) this.f3007l).a();
            if (!TextUtils.isEmpty(strA)) {
                this.f2999d = strA;
            }
        }
        j();
    }

    public void m() {
        if (this.f3006k == null || SystemClock.elapsedRealtime() >= this.f3005j + f(this.f3004i)) {
            if (this.f3001f == null) {
                this.f3001f = new a0.r("manifestLoader");
            }
            if (this.f3001f.d()) {
                return;
            }
            this.f3002g = new a0.y(this.f2999d, this.f2997b, this.f2996a);
            this.f3003h = SystemClock.elapsedRealtime();
            this.f3001f.g(this.f3002g, this);
            i();
        }
    }

    @Override // a0.r.a
    public void n(r.c cVar, IOException iOException) {
        if (this.f3002g != cVar) {
            return;
        }
        this.f3004i++;
        this.f3005j = SystemClock.elapsedRealtime();
        c cVar2 = new c(iOException);
        this.f3006k = cVar2;
        h(cVar2);
    }

    public void o(Looper looper, b bVar) {
        new e(new a0.y(this.f2999d, this.f2997b, this.f2996a), looper, bVar).b();
    }

    @Override // a0.r.a
    public void v(r.c cVar) {
    }

    public j(String str, a0.x xVar, y.a aVar, Handler handler, a aVar2) {
        this.f2996a = aVar;
        this.f2999d = str;
        this.f2997b = xVar;
        this.f2998c = handler;
    }
}
