package G;

import G.a;
import a0.InterfaceC0147b;
import a0.i;
import a0.r;
import android.media.MediaExtractor;
import android.os.Looper;
import android.util.Log;
import b0.k;
import b0.o;
import n.C0633A;
import n.x;

/* JADX INFO: loaded from: classes.dex */
abstract class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    protected InterfaceC0147b f714a = new i(65536);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f715b;

    static class a extends b {

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

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

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

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

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private G.a f720g;

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

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

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

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        private final Object f724k;

        a(String str, MediaExtractor mediaExtractor, c cVar) {
            super(str);
            this.f723j = 0;
            this.f716c = "SingleExtractorHandler" + str;
            this.f717d = mediaExtractor;
            this.f724k = new Object();
            this.f718e = cVar;
            this.f719f = mediaExtractor.getTrackCount();
            this.f722i = Looper.myLooper();
        }

        @Override // G.b
        public boolean a(int i2, long j2) {
            if (this.f720g.i(i2)) {
                return true;
            }
            this.f720g.f(i2, j2);
            l(i2);
            boolean zH = this.f720g.h(i2);
            o.c(this.f716c, 8, " !singleExtractorTracksLoadable.isEmpty(", Integer.valueOf(i2), ") =  ", Boolean.valueOf(!zH));
            return !zH;
        }

        @Override // G.b
        public void b(int i2, long j2) {
            o.d(this.f716c, "disable track = " + i2, 8);
            if (this.f721h.d()) {
                o.d(this.f716c, "Loader is loading. Cancel it.", 8);
                this.f721h.c();
            }
            if (((r.c) this.f720g).m()) {
                this.f720g = this.f720g.p();
            }
            this.f720g.v(i2, j2);
        }

        @Override // G.b
        public void c(int i2, long j2) {
            o.d(this.f716c, "enable track = " + i2 + ", positionUs = " + j2 + ", isEndOfStream=" + this.f720g.n(i2), 8);
            if (this.f721h.d()) {
                o.d(this.f716c, "Loader is loading. Cancel it.", 8);
                this.f721h.c();
            }
            if (((r.c) this.f720g).m()) {
                this.f720g = this.f720g.p();
            }
            this.f720g.d(i2, j2);
            x xVarA = this.f720g.a(i2);
            if (xVarA == null || j2 == 0) {
                return;
            }
            if (k.g(xVarA.f5842g) || (k.d(xVarA.f5842g) && this.f720g.n(i2))) {
                this.f720g.s(j2, true);
            }
        }

        @Override // G.b
        public long d() {
            if (this.f720g.i(0)) {
                return -3L;
            }
            long jMax = Long.MIN_VALUE;
            for (int i2 = 0; i2 < this.f719f; i2++) {
                x xVarA = this.f720g.a(i2);
                if (this.f720g.r(i2) && xVarA != null && !k.e(xVarA.f5842g)) {
                    jMax = Math.max(this.f720g.j(i2), jMax);
                }
            }
            return jMax;
        }

        @Override // G.b
        public boolean e(int i2) {
            return this.f720g.n(i2);
        }

        @Override // G.b
        public void f(long j2) {
            this.f720g = new a.C0005a(this.f715b, this.f717d, this.f714a, this.f719f, this.f723j);
            this.f721h = new r("single-loader");
        }

        @Override // G.b
        public int g(int i2, C0633A c0633a) {
            return this.f720g.o(i2, c0633a);
        }

        @Override // G.b
        public void h() {
            Log.i(this.f716c, "release()");
            if (this.f721h.d()) {
                this.f721h.c();
            }
            this.f721h.e();
            this.f720g.release();
            super.h();
        }

        @Override // G.b
        public long i(long j2) {
            if (this.f720g.l(j2)) {
                return j2;
            }
            o.d(this.f716c, "Can not find in cached samples", 8);
            if (this.f721h.d()) {
                o.d(this.f716c, "Loader is loading. Cancel it.", 8);
                this.f721h.c();
            }
            if (((r.c) this.f720g).m()) {
                this.f720g = this.f720g.p();
            }
            return this.f720g.s(j2, true);
        }

        @Override // G.b
        public void j(long j2) {
            this.f720g.k(j2);
            o.d(this.f716c, "setting avg bitrate=" + j2, 8);
        }

        @Override // G.b
        public void k(int i2) {
            this.f723j = i2;
            G.a aVar = this.f720g;
            if (aVar != null) {
                aVar.g(i2);
            }
        }

        public void l(int i2) {
            synchronized (this.f724k) {
                try {
                    if (this.f721h.d()) {
                        int i3 = ((a.C0005a) this.f720g).f705r;
                        if (i3 == 0 || this.f714a.d() < i3 || this.f720g.h(i2)) {
                            this.f720g.t();
                        }
                    } else {
                        Log.d(this.f716c, "[Performance]startLoading");
                        this.f721h.h(this.f722i, (r.c) this.f720g, this.f718e);
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    b(String str) {
        this.f715b = str;
    }

    public abstract boolean a(int i2, long j2);

    public abstract void b(int i2, long j2);

    public abstract void c(int i2, long j2);

    public abstract long d();

    public abstract boolean e(int i2);

    public abstract void f(long j2);

    public abstract int g(int i2, C0633A c0633a);

    public void h() {
        this.f714a.f(0);
    }

    public abstract long i(long j2);

    public abstract void j(long j2);

    public abstract void k(int i2);
}
