package G;

import a0.InterfaceC0147b;
import a0.r;
import android.media.MediaExtractor;
import android.os.SystemClock;
import android.util.Log;
import android.util.SparseArray;
import androidx.media3.session.legacy.PlaybackStateCompat;
import b0.D;
import b0.k;
import b0.n;
import b0.o;
import java.util.concurrent.Semaphore;
import n.C0633A;
import n.m;
import n.s;
import n.u;
import n.x;
import v.C0727c;

/* JADX INFO: loaded from: classes.dex */
interface a {
    x a(int i2);

    void d(int i2, long j2);

    boolean f(int i2, long j2);

    void g(int i2);

    boolean h(int i2);

    boolean i(int i2);

    long j(int i2);

    void k(long j2);

    boolean l(long j2);

    boolean n(int i2);

    int o(int i2, C0633A c0633a);

    a p();

    boolean r(int i2);

    void release();

    long s(long j2, boolean z2);

    void t();

    MediaExtractor v(int i2, long j2);

    /* JADX INFO: renamed from: G.a$a, reason: collision with other inner class name */
    public static class C0005a implements r.c, a {

        /* JADX INFO: renamed from: A, reason: collision with root package name */
        private boolean f670A;

        /* JADX INFO: renamed from: B, reason: collision with root package name */
        private a f671B;

        /* JADX INFO: renamed from: C, reason: collision with root package name */
        private boolean f672C;

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

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

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

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

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

        /* JADX INFO: renamed from: I, reason: collision with root package name */
        private String f678I;

        /* JADX INFO: renamed from: J, reason: collision with root package name */
        private boolean[] f679J;

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

        /* JADX INFO: renamed from: L, reason: collision with root package name */
        private long[] f681L;

        /* JADX INFO: renamed from: M, reason: collision with root package name */
        private long[] f682M;

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

        /* JADX INFO: renamed from: O, reason: collision with root package name */
        private boolean f684O;

        /* JADX INFO: renamed from: P, reason: collision with root package name */
        private boolean f685P;

        /* JADX INFO: renamed from: Q, reason: collision with root package name */
        Runtime f686Q;

        /* JADX INFO: renamed from: R, reason: collision with root package name */
        long f687R;

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

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private final InterfaceC0147b f691d;

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

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

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private final Semaphore f694g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private final SparseArray f695h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private final boolean[] f696i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        private final boolean[] f697j;

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

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        private final x[] f699l;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public final int f700m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final int f701n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public final int f702o;

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

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

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        int f705r;

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

        /* JADX INFO: renamed from: t, reason: collision with root package name */
        private boolean f707t;

        /* JADX INFO: renamed from: u, reason: collision with root package name */
        private boolean f708u;

        /* JADX INFO: renamed from: v, reason: collision with root package name */
        private boolean[] f709v;

        /* JADX INFO: renamed from: w, reason: collision with root package name */
        private boolean f710w;

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

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

        /* JADX INFO: renamed from: z, reason: collision with root package name */
        private boolean f713z;

        /* JADX WARN: Removed duplicated region for block: B:69:0x0238  */
        /* JADX WARN: Removed duplicated region for block: B:79:0x025f  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        C0005a(java.lang.String r17, android.media.MediaExtractor r18, a0.InterfaceC0147b r19, int r20, int r21) {
            /*
                Method dump skipped, instruction units count: 706
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: G.a.C0005a.<init>(java.lang.String, android.media.MediaExtractor, a0.b, int, int):void");
        }

        private void b() {
            long j2 = this.f680K;
            if (j2 >= 200000000) {
                this.f705r = 209715200;
                this.f704q = 10000000L;
                this.f706s = 16777216;
            } else if (j2 >= 150000000) {
                this.f705r = 157286400;
                this.f704q = 8000000L;
                this.f706s = 16777216;
            } else if (j2 >= 100000000 || e() > 9437184) {
                this.f705r = 104857600;
                this.f704q = 6000000L;
                this.f706s = 16777216;
            } else if (this.f680K >= 30000000 || e() > 2073600) {
                this.f705r = 62914560;
                this.f704q = 2000000L;
                this.f706s = 10485760;
            } else {
                this.f705r = 20971520;
                this.f704q = 2000000L;
                this.f706s = 5242880;
            }
            if (n.e()) {
                this.f705r = 62914560;
                this.f704q = 6000000L;
                this.f706s = 6291456;
            }
            this.f687R = this.f686Q.maxMemory();
            o.d(this.f688a, "config: MAX_ALLOCATION_SIZE=" + (this.f705r / 1048576) + "M, MAX_BUFFER_TIME_US_FOR_PRIMARY_TRACK=" + (this.f704q / 1000000) + "s, SAMPLE_BUFFER_CAPACITY=" + (this.f706s / 1048576) + "M dalvikMax:" + (this.f687R / PlaybackStateCompat.ACTION_SET_CAPTIONING_ENABLED) + "M", 8);
        }

        private void c(long j2) {
            for (int i2 = 0; i2 < this.f692e; i2++) {
                if (!this.f696i[i2] && !((C0727c) this.f695h.valueAt(i2)).s()) {
                    ((C0727c) this.f695h.valueAt(i2)).j(j2);
                    o.c(this.f688a, 8, "track[", Integer.valueOf(i2), "] discardUntil ", Long.valueOf(j2));
                }
            }
        }

        private int e() {
            int i2;
            int i3;
            int i4 = this.f674E;
            if (i4 >= 0) {
                x xVarA = a(i4);
                i2 = xVarA.f5831L;
                i3 = xVarA.f5832M;
            } else {
                i2 = 0;
                i3 = 0;
            }
            return i2 * i3;
        }

        private boolean w(x xVar) {
            String strC;
            String str = xVar.f5842g;
            if ("video/dolby-vision".equals(str)) {
                xVar.r();
                if (D.f2965a < 24 || (strC = u.c(xVar.r(), false)) == null) {
                    return false;
                }
                str = str + "#" + strC;
            }
            if (k.g(str)) {
                return "video/x-unknown".equals(str) || s.f5653a.c(str, false) != null;
            }
            return false;
        }

        private boolean x() {
            boolean z2 = true;
            for (int i2 = 0; i2 < this.f692e; i2++) {
                C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
                long jN = c0727c.n() - this.f698k[i2];
                if (this.f696i[i2] && this.f697j[i2]) {
                    if (c0727c.s() || jN < 500000) {
                        o.c(this.f688a, 8, "enabled primary track should buffer more, sampledTimeUs=", Long.valueOf(jN));
                        return true;
                    }
                    z2 &= jN < this.f704q;
                }
            }
            return (this.f691d.d() <= this.f705r) & z2;
        }

        private void y(boolean z2) {
            int i2;
            for (int i3 = 0; i3 < this.f692e; i3++) {
                x xVarA = a(i3);
                if ((k.e(xVarA.f5842g) || "application/eia-608".equals(xVarA.f5842g) || (k.d(xVarA.f5842g) && !"audio/x-unknown".equals(xVarA.f5842g))) && ((i2 = this.f677H) == -1 || xVarA.f5850n0 == i2)) {
                    if (z2) {
                        o.d(this.f688a, "selectTrack track= " + i3, 8);
                        this.f690c.selectTrack(i3);
                        if (k.d(xVarA.f5842g)) {
                            this.f675F = i3;
                        }
                        if (this.f677H == -1) {
                            this.f677H = xVarA.f5850n0;
                        }
                    } else {
                        o.d(this.f688a, "unselectTrack track= " + i3, 8);
                        this.f690c.unselectTrack(i3);
                        C0727c c0727c = (C0727c) this.f695h.valueAt(i3);
                        if (c0727c != null) {
                            c0727c.h();
                        }
                        this.f698k[i3] = -1;
                    }
                }
            }
        }

        public void A(String str, int i2) {
            int i3;
            int i4;
            int i5;
            if (k.g(str) && (i5 = this.f673D) != -1 && i5 != i2) {
                this.f690c.unselectTrack(i5);
                ((C0727c) this.f695h.valueAt(this.f673D)).h();
                return;
            }
            if (k.e(str) && this.f685P && (i4 = this.f676G) != i2 && i4 != -1) {
                this.f690c.unselectTrack(i4);
                ((C0727c) this.f695h.valueAt(this.f676G)).h();
            } else {
                if (!k.d(str) || !this.f684O || (i3 = this.f675F) == i2 || i3 == -1) {
                    return;
                }
                this.f690c.unselectTrack(i3);
                ((C0727c) this.f695h.valueAt(this.f675F)).h();
            }
        }

        @Override // G.a
        public x a(int i2) {
            x xVar = this.f699l[i2];
            if (xVar != null) {
                return xVar;
            }
            x xVarB = m.b(this.f690c.getTrackFormat(i2));
            if (this.f678I != null && ("video/wvc1".equals(xVarB.f5842g) || "video/VC1".equals(xVarB.f5842g) ? this.f678I.toLowerCase().contains("matroska") || this.f678I.toLowerCase().contains("avi") || this.f678I.toLowerCase().contains("asf") : !"video/x-ms-wmv".equals(xVarB.f5842g) ? !(!"video/hevc".equals(xVarB.f5842g) || !this.f678I.toLowerCase().contains("mpeg4")) : this.f678I.toLowerCase().contains("asf"))) {
                xVarB.f5853q0 = 1;
            }
            this.f699l[i2] = xVarB;
            return xVarB;
        }

        @Override // G.a
        public void d(int i2, long j2) {
            if (this.f696i[i2]) {
                return;
            }
            String str = ((C0727c) this.f695h.valueAt(i2)).m().f5842g;
            int i3 = ((C0727c) this.f695h.valueAt(i2)).m().f5850n0;
            if (k.g(str)) {
                A(str, i2);
                this.f690c.selectTrack(i2);
                this.f674E = i2;
                this.f673D = -1;
            } else if (this.f685P && k.e(str)) {
                A(str, i2);
                this.f690c.selectTrack(i2);
                this.f676G = i2;
                Log.d(this.f688a, "selectTrack text index: " + i2);
            } else {
                if (this.f684O && k.d(str)) {
                    A(str, i2);
                    this.f690c.selectTrack(i2);
                    Log.d(this.f688a, "selectTrack audio index: " + i2);
                } else if (i3 != this.f677H) {
                    for (int i4 = 0; i4 < this.f690c.getTrackCount(); i4++) {
                        x xVarM = ((C0727c) this.f695h.valueAt(i4)).m();
                        if (!k.g(xVarM.f5842g)) {
                            int i5 = xVarM.f5850n0;
                            if (i5 == this.f677H) {
                                this.f690c.unselectTrack(i4);
                                ((C0727c) this.f695h.valueAt(i4)).h();
                            } else if (i5 == i3) {
                                this.f690c.selectTrack(i4);
                            }
                        }
                    }
                    this.f677H = i3;
                } else {
                    int i6 = this.f674E;
                    if (i6 >= 0) {
                        j2 = Math.min(j2, this.f698k[i6]);
                    }
                    c(j2);
                }
                this.f675F = i2;
            }
            this.f696i[i2] = true;
            this.f713z = true;
            if (this.f690c.getTrackCount() == 1 && k.g(str)) {
                this.f672C = true;
            }
        }

        @Override // G.a
        public boolean f(int i2, long j2) {
            if (this.f691d.d() <= this.f705r) {
                return true;
            }
            c(j2);
            return true;
        }

        @Override // G.a
        public void g(int i2) {
            o.d(this.f688a, "setting focus mode " + i2, 8);
            if (i2 == 2) {
                y(false);
            } else {
                y(true);
            }
            this.f683N = i2;
        }

        @Override // G.a
        public boolean h(int i2) {
            return this.f697j[i2] && ((C0727c) this.f695h.valueAt(i2)).s();
        }

        @Override // G.a
        public boolean i(int i2) {
            int i3;
            if (!this.f708u && i2 == this.f675F) {
                C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
                long j2 = c0727c.m().f5856y;
                if (c0727c.s() && j2 > 0 && (i3 = this.f674E) >= 0 && ((C0727c) this.f695h.valueAt(i3)).m().f5856y - j2 >= 10000000 && this.f698k[i2] - j2 >= -500000) {
                    return true;
                }
            }
            return this.f708u;
        }

        @Override // G.a
        public long j(int i2) {
            String str;
            if (this.f672C || !this.f697j[i2] || ((C0727c) this.f695h.valueAt(i2)).m().f5856y == -1) {
                return -1L;
            }
            long jN = ((C0727c) this.f695h.valueAt(i2)).n();
            if (this.f697j.length <= 6 || this.f711x > 0 || jN >= 3500000.0d || SystemClock.elapsedRealtime() >= 120000 || (str = this.f678I) == null || !str.toLowerCase().contains("matroska")) {
                return jN;
            }
            return Long.MIN_VALUE;
        }

        @Override // G.a
        public void k(long j2) {
            this.f680K = j2;
        }

        @Override // G.a
        public boolean l(long j2) {
            boolean zU;
            String str = this.f678I;
            if (str != null && str.toLowerCase().contains("ape")) {
                for (int i2 = 0; i2 < this.f692e; i2++) {
                    ((C0727c) this.f695h.valueAt(i2)).h();
                }
                return false;
            }
            int i3 = this.f674E;
            if (i3 >= 0) {
                zU = ((C0727c) this.f695h.valueAt(i3)).u(j2);
                if (zU) {
                    C0633A c0633a = new C0633A(0);
                    if (((C0727c) this.f695h.valueAt(this.f674E)).l(c0633a)) {
                        j2 = c0633a.f5412e;
                    }
                }
            } else {
                zU = true;
            }
            for (int i4 = 0; i4 < this.f692e; i4++) {
                if (this.f696i[i4] && i4 != this.f674E) {
                    zU &= ((C0727c) this.f695h.valueAt(i4)).u(j2);
                }
            }
            return zU;
        }

        @Override // a0.r.c
        public boolean m() {
            return this.f707t;
        }

        @Override // G.a
        public boolean n(int i2) {
            if (!this.f708u) {
                return false;
            }
            if (this.f697j[i2]) {
                return this.f696i[i2] && ((C0727c) this.f695h.valueAt(i2)).s();
            }
            boolean zS = ((C0727c) this.f695h.valueAt(i2)).s();
            int i3 = 0;
            while (true) {
                boolean[] zArr = this.f696i;
                if (i3 >= zArr.length) {
                    return zS;
                }
                zS &= (zArr[i3] && this.f697j[i3] && !((C0727c) this.f695h.valueAt(i2)).s()) ? false : true;
                i3++;
            }
        }

        @Override // G.a
        public int o(int i2, C0633A c0633a) {
            int i3;
            int i4;
            if (this.f711x == -1 && (i4 = this.f674E) >= 0 && !this.f679J[i4] && ((C0727c) this.f695h.valueAt(i4)).s()) {
                return -2;
            }
            C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
            if (2 == this.f683N && k.d(c0727c.m().f5842g)) {
                return -2;
            }
            if (!c0727c.s() && c0727c.p(c0633a)) {
                o.c(this.f688a, 8, "[", c0727c.m().f5842g, "] readData timeUs = ", Long.valueOf(c0633a.f5412e), ", size = ", Integer.valueOf(c0633a.f5410c), ", flags = ", Integer.valueOf(c0633a.f5411d));
                long[] jArr = this.f698k;
                jArr[i2] = Math.max(c0633a.f5412e, jArr[i2]);
                return -3;
            }
            if (k.d(c0727c.m().f5842g)) {
                long j2 = c0727c.m().f5856y;
                if (j2 > 0 && (i3 = this.f674E) >= 0 && ((C0727c) this.f695h.valueAt(i3)).m().f5856y - j2 >= 10000000 && this.f698k[i2] - j2 >= -500000) {
                    Log.d(this.f688a, "Audio ends 10s earlier than video. Return EOS.");
                    return -1;
                }
            }
            return -2;
        }

        @Override // G.a
        public a p() {
            o.d(this.f688a, "cloned = " + this.f670A + ", clonedThis = " + this.f671B, 8);
            if (!this.f670A) {
                this.f671B = new C0005a(this);
                this.f670A = true;
            }
            return this.f671B;
        }

        /* JADX WARN: Code restructure failed: missing block: B:44:0x00eb, code lost:
        
            r8 = r22;
            r7 = true;
         */
        /* JADX WARN: Code restructure failed: missing block: B:66:0x01b7, code lost:
        
            r9 = z();
         */
        /* JADX WARN: Code restructure failed: missing block: B:67:0x01bb, code lost:
        
            if (r3 != false) goto L93;
         */
        /* JADX WARN: Code restructure failed: missing block: B:69:0x01c1, code lost:
        
            if (r42.f679J[r13] != false) goto L92;
         */
        /* JADX WARN: Code restructure failed: missing block: B:70:0x01c3, code lost:
        
            android.util.Log.d(r42.f688a, "[Performance]track " + r13 + ": [" + ((v.C0727c) r42.f695h.valueAt(r13)).m().f5842g + "] 1st sample put into queue: timeUs = " + r7 + ", size = " + r14 + ", flags = " + r15 + ", allocator.getTotalBytesAllocated() = " + r42.f691d.d() + ", continueLoading = " + r9 + ", durationUs = " + (android.os.SystemClock.elapsedRealtimeNanos() - r10));
            r3 = r42.f679J;
            r5 = true;
            r3[r13] = true;
         */
        /* JADX WARN: Code restructure failed: missing block: B:71:0x0235, code lost:
        
            if (r42.f711x != (-1)) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:72:0x0237, code lost:
        
            r6 = r42.f674E;
         */
        /* JADX WARN: Code restructure failed: missing block: B:73:0x0239, code lost:
        
            if (r13 != r6) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:74:0x023b, code lost:
        
            r10 = r42.f675F;
         */
        /* JADX WARN: Code restructure failed: missing block: B:75:0x023d, code lost:
        
            if (r10 < 0) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:77:0x0241, code lost:
        
            if (r3[r10] == false) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:78:0x0243, code lost:
        
            r3 = r42.f698k;
         */
        /* JADX WARN: Code restructure failed: missing block: B:79:0x0249, code lost:
        
            if (r3[r6] != (-1)) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:81:0x024f, code lost:
        
            if (r3[r10] != (-1)) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:82:0x0251, code lost:
        
            r3 = new n.C0633A(0);
         */
        /* JADX WARN: Code restructure failed: missing block: B:83:0x0264, code lost:
        
            if (((v.C0727c) r42.f695h.valueAt(r42.f675F)).l(r3) == false) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:84:0x0266, code lost:
        
            r10 = r3.f5412e;
         */
        /* JADX WARN: Code restructure failed: missing block: B:85:0x0268, code lost:
        
            if (r7 < 0) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:87:0x026c, code lost:
        
            if (r10 < 0) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:89:0x0274, code lost:
        
            if ((r7 - r10) <= 500000) goto L91;
         */
        /* JADX WARN: Code restructure failed: missing block: B:90:0x0276, code lost:
        
            ((v.C0727c) r42.f695h.valueAt(r42.f675F)).h();
            android.util.Log.d(r42.f688a, "First video sample's PTS is greater than the first audio sample over 500ms. Drop all audio samples before the first video sample.");
         */
        /* JADX WARN: Code restructure failed: missing block: B:91:0x028a, code lost:
        
            r10 = 1000;
         */
        /* JADX WARN: Code restructure failed: missing block: B:92:0x028d, code lost:
        
            r5 = true;
            r3 = r42.f688a;
            r27 = java.lang.Integer.valueOf(r13);
            r6 = ((v.C0727c) r42.f695h.valueAt(r13)).m().f5842g;
            r31 = java.lang.Long.valueOf(r7);
            r33 = java.lang.Integer.valueOf(r14);
            r35 = java.lang.Integer.valueOf(r15);
            r37 = java.lang.Integer.valueOf(r42.f691d.d());
            r39 = java.lang.Boolean.valueOf(r9);
            r7 = android.os.SystemClock.elapsedRealtimeNanos() - r10;
            r10 = 1000;
            b0.o.c(r3, 8, "track ", r27, ": [", r6, "] sample put into queue: timeUs = ", r31, ", size = ", r33, ", flags = ", r35, ", allocator.getTotalBytesAllocated() = ", r37, ", continueLoading = ", r39, ", duration = ", java.lang.Long.valueOf(r7 / 1000));
         */
        /* JADX WARN: Code restructure failed: missing block: B:93:0x02e5, code lost:
        
            r5 = true;
         */
        /* JADX WARN: Code restructure failed: missing block: B:94:0x02e7, code lost:
        
            r7 = r5;
            r5 = r10;
            r8 = r22;
         */
        @Override // a0.r.c
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void q() throws java.lang.InterruptedException {
            /*
                Method dump skipped, instruction units count: 791
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: G.a.C0005a.q():void");
        }

        @Override // G.a
        public boolean r(int i2) {
            return this.f696i[i2];
        }

        @Override // G.a
        public void release() {
            synchronized (this.f693f) {
                try {
                    if (this.f690c != null) {
                        Log.i(this.f688a, "extractor release+++");
                        this.f690c.release();
                        Log.i(this.f688a, "extractor release---");
                        this.f690c = null;
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
            for (int i2 = 0; i2 < this.f695h.size(); i2++) {
                C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
                if (c0727c != null) {
                    c0727c.h();
                }
            }
        }

        @Override // G.a
        public long s(long j2, boolean z2) {
            o.d(this.f688a, "[Tracks] seekTo lastSeekTimeUs = " + this.f711x + ", position = " + j2 + ", this = " + toString(), 8);
            if (this.f711x == j2 && !z2) {
                return j2;
            }
            o.d(this.f688a, "[Tracks] seekTo position = " + j2, 8);
            this.f690c.seekTo(j2, 0);
            for (int i2 = 0; i2 < this.f692e; i2++) {
                ((C0727c) this.f695h.valueAt(i2)).h();
                this.f698k[i2] = -1;
                this.f709v[i2] = true;
            }
            this.f710w = true;
            this.f708u = false;
            this.f711x = j2;
            return this.f690c.getSampleTime();
        }

        @Override // G.a
        public void t() {
            o.d(this.f688a, "[Tracks] tryToNextLoad", 8);
            if (this.f694g.availablePermits() == 0 && z()) {
                this.f694g.release();
            }
        }

        @Override // a0.r.c
        public void u() {
            synchronized (this.f693f) {
                Log.i(this.f688a, "[Tracks] cancelLoad");
                this.f707t = true;
            }
        }

        @Override // G.a
        public MediaExtractor v(int i2, long j2) {
            boolean[] zArr = this.f696i;
            zArr[i2] = false;
            boolean z2 = false;
            for (boolean z3 : zArr) {
                z2 |= z3;
            }
            this.f713z = z2;
            x xVarA = a(i2);
            C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
            if (k.g(xVarA.f5842g)) {
                this.f690c.unselectTrack(i2);
                this.f674E = -1;
                if (c0727c != null) {
                    c0727c.h();
                }
                Log.i(this.f688a, "unselectTrack video track index: " + i2);
                return null;
            }
            if (k.e(xVarA.f5842g) && this.f685P) {
                this.f690c.unselectTrack(i2);
                this.f676G = -1;
                if (c0727c != null) {
                    c0727c.h();
                }
                Log.d(this.f688a, "unselectTrack text index: " + i2);
                return null;
            }
            if (k.d(xVarA.f5842g)) {
                this.f675F = -1;
                if (this.f684O) {
                    this.f690c.unselectTrack(i2);
                    if (c0727c != null) {
                        c0727c.h();
                    }
                    Log.d(this.f688a, "unselectTrack audio index: " + i2);
                }
            }
            if (j2 < 0) {
                return null;
            }
            c(j2);
            return null;
        }

        public boolean z() {
            if (this.f683N != 0) {
                return x();
            }
            boolean z2 = true;
            for (int i2 = 0; i2 < this.f692e; i2++) {
                C0727c c0727c = (C0727c) this.f695h.valueAt(i2);
                if (this.f696i[i2] && this.f697j[i2]) {
                    long jN = c0727c.n() - this.f698k[i2];
                    if (c0727c.s() || (jN < 500000 && this.f698k[i2] != -1)) {
                        boolean z3 = this.f683N == 0 ? ((long) this.f691d.d()) <= (this.f687R * 5) / 8 : true;
                        o.c(this.f688a, 8, "enabled primary track[", Integer.valueOf(i2), "] sampledTimeUs[", Long.valueOf(jN), "] less than 500ms, shouldBuffering = ", Boolean.valueOf(z3));
                        return z3;
                    }
                    if (n.e()) {
                        if (this.f698k[i2] == -1) {
                            return this.f691d.d() <= this.f705r;
                        }
                        z2 &= jN < this.f704q;
                    } else if (this.f684O || this.f685P) {
                        if (this.f698k[i2] == -1) {
                            return this.f691d.d() <= this.f705r;
                        }
                        z2 &= jN < 1000000;
                        o.c(this.f688a, 8, "disablePrebufferForMkv sampledTimeUs:", Long.valueOf(jN), ", shouldBuffering = ", Boolean.valueOf(z2));
                    }
                }
            }
            return (this.f691d.d() <= this.f705r) & z2;
        }

        C0005a(C0005a c0005a) {
            this.f700m = 2073600;
            this.f701n = 9437184;
            this.f702o = 35389440;
            this.f703p = 500000L;
            this.f711x = -1L;
            this.f673D = -1;
            this.f674E = -1;
            this.f675F = -1;
            this.f676G = -1;
            this.f683N = 0;
            this.f686Q = Runtime.getRuntime();
            String str = c0005a.f689b;
            this.f689b = str;
            String str2 = "TracksLoadable" + str;
            this.f688a = str2;
            o.d(str2, "copy TracksLoadable", 8);
            this.f690c = c0005a.f690c;
            this.f691d = c0005a.f691d;
            this.f692e = c0005a.f692e;
            this.f693f = new Object();
            this.f694g = new Semaphore(1);
            this.f695h = c0005a.f695h;
            this.f696i = c0005a.f696i;
            this.f705r = c0005a.f705r;
            this.f706s = c0005a.f706s;
            this.f704q = c0005a.f704q;
            this.f680K = c0005a.f680K;
            this.f681L = c0005a.f681L;
            this.f682M = c0005a.f682M;
            this.f697j = c0005a.f697j;
            this.f698k = c0005a.f698k;
            this.f709v = c0005a.f709v;
            this.f711x = c0005a.f711x;
            this.f713z = c0005a.f713z;
            this.f672C = c0005a.f672C;
            this.f673D = c0005a.f673D;
            this.f674E = c0005a.f674E;
            this.f675F = c0005a.f675F;
            this.f708u = c0005a.f708u;
            this.f677H = c0005a.f677H;
            this.f678I = c0005a.f678I;
            this.f679J = c0005a.f679J;
            this.f683N = c0005a.f683N;
            this.f699l = c0005a.f699l;
            this.f684O = c0005a.f684O;
            this.f685P = c0005a.f685P;
        }
    }
}
