package com.google.android.exoplayer2.source.b;

import android.os.Handler;
import android.text.TextUtils;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.a$a;
import com.google.android.exoplayer2.source.b.a.e;
import com.google.android.exoplayer2.source.b.a.e.b;
import com.google.android.exoplayer2.source.b.j.a;
import com.google.android.exoplayer2.source.h;
import com.google.android.exoplayer2.source.l;
import com.google.android.exoplayer2.source.o;
import com.google.android.exoplayer2.source.p;
import com.tencent.matrix.trace.core.AppMethodBeat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;

public final class g implements b, a, h {
    private p aNe;
    private final int bgC;
    private final com.google.android.exoplayer2.h.b bgF;
    private h.a bgq;
    private final k bip = new k();
    final e bir;
    private final d bjb;
    private final a$a bjc;
    private final IdentityHashMap<l, Integer> bjd = new IdentityHashMap();
    final Handler bje = new Handler();
    private int bjf;
    j[] bjg = new j[0];
    private j[] bjh = new j[0];
    private com.google.android.exoplayer2.source.e bji;

    public g(e eVar, d dVar, int i, a$a a_a, com.google.android.exoplayer2.h.b bVar) {
        AppMethodBeat.i(125910);
        this.bir = eVar;
        this.bjb = dVar;
        this.bgC = i;
        this.bjc = a_a;
        this.bgF = bVar;
        AppMethodBeat.o(125910);
    }

    public final void a(h.a aVar, long j) {
        int i;
        com.google.android.exoplayer2.source.b.a.a.a aVar2;
        List list;
        int i2;
        int i3;
        AppMethodBeat.i(125911);
        this.bgq = aVar;
        this.bir.bkF.add(this);
        com.google.android.exoplayer2.source.b.a.a aVar3 = this.bir.biH;
        ArrayList arrayList = new ArrayList(aVar3.bjF);
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        int i4 = 0;
        while (true) {
            i = i4;
            if (i >= arrayList.size()) {
                break;
            }
            aVar2 = (com.google.android.exoplayer2.source.b.a.a.a) arrayList.get(i);
            if (aVar2.aOv.height > 0 || a(aVar2, "avc")) {
                arrayList2.add(aVar2);
            } else if (a(aVar2, "mp4a")) {
                arrayList3.add(aVar2);
            }
            i4 = i + 1;
        }
        if (arrayList2.isEmpty()) {
            if (arrayList3.size() < arrayList.size()) {
                arrayList.removeAll(arrayList3);
            }
            Object list2 = arrayList;
        } else {
            list2 = arrayList2;
        }
        List list3 = aVar3.bjG;
        List list4 = aVar3.bjH;
        this.bjg = new j[((list3.size() + 1) + list4.size())];
        this.bjf = this.bjg.length;
        com.google.android.exoplayer2.i.a.checkArgument(!list2.isEmpty());
        com.google.android.exoplayer2.source.b.a.a.a[] aVarArr = new com.google.android.exoplayer2.source.b.a.a.a[list2.size()];
        list2.toArray(aVarArr);
        j a = a(0, aVarArr, aVar3.bjp, aVar3.bit, j);
        i4 = 1;
        this.bjg[0] = a;
        a.aJ(true);
        a.sz();
        i = 0;
        while (true) {
            i2 = i4;
            i3 = i;
            if (i3 >= list3.size()) {
                break;
            }
            a = a(1, new com.google.android.exoplayer2.source.b.a.a.a[]{(com.google.android.exoplayer2.source.b.a.a.a) list3.get(i3)}, null, Collections.emptyList(), j);
            i4 = i2 + 1;
            this.bjg[i2] = a;
            a.sz();
            i = i3 + 1;
        }
        for (i3 = 0; i3 < list4.size(); i3++) {
            a = a(3, new com.google.android.exoplayer2.source.b.a.a.a[]{(com.google.android.exoplayer2.source.b.a.a.a) list4.get(i3)}, null, Collections.emptyList(), j);
            a.es(0).f(aVar2.aOv);
            a.bgQ = true;
            a.sB();
            i4 = i2 + 1;
            this.bjg[i2] = a;
            i2 = i4;
        }
        this.bjh = this.bjg;
        AppMethodBeat.o(125911);
    }

    public final void rR() {
        AppMethodBeat.i(125912);
        for (j jVar : this.bjg) {
            jVar.bjo.rW();
        }
        AppMethodBeat.o(125912);
    }

    public final p rS() {
        return this.aNe;
    }

    /* JADX WARNING: Removed duplicated region for block: B:101:0x0213  */
    public final long a(com.google.android.exoplayer2.g.f[] r24, boolean[] r25, com.google.android.exoplayer2.source.l[] r26, boolean[] r27, long r28) {
        /*
        r23 = this;
        r4 = 125913; // 0x1ebd9 float:1.76442E-40 double:6.22093E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r4);
        r0 = r24;
        r4 = r0.length;
        r12 = new int[r4];
        r0 = r24;
        r4 = r0.length;
        r13 = new int[r4];
        r4 = 0;
        r5 = r4;
    L_0x0012:
        r0 = r24;
        r4 = r0.length;
        if (r5 >= r4) goto L_0x005c;
    L_0x0017:
        r4 = r26[r5];
        if (r4 != 0) goto L_0x0048;
    L_0x001b:
        r4 = -1;
    L_0x001c:
        r12[r5] = r4;
        r4 = -1;
        r13[r5] = r4;
        r4 = r24[r5];
        if (r4 == 0) goto L_0x0044;
    L_0x0025:
        r4 = r24[r5];
        r6 = r4.tf();
        r4 = 0;
    L_0x002c:
        r0 = r23;
        r7 = r0.bjg;
        r7 = r7.length;
        if (r4 >= r7) goto L_0x0044;
    L_0x0033:
        r0 = r23;
        r7 = r0.bjg;
        r7 = r7[r4];
        r7 = r7.aNe;
        r7 = r7.a(r6);
        r8 = -1;
        if (r7 == r8) goto L_0x0059;
    L_0x0042:
        r13[r5] = r4;
    L_0x0044:
        r4 = r5 + 1;
        r5 = r4;
        goto L_0x0012;
    L_0x0048:
        r0 = r23;
        r4 = r0.bjd;
        r6 = r26[r5];
        r4 = r4.get(r6);
        r4 = (java.lang.Integer) r4;
        r4 = r4.intValue();
        goto L_0x001c;
    L_0x0059:
        r4 = r4 + 1;
        goto L_0x002c;
    L_0x005c:
        r7 = 0;
        r0 = r23;
        r4 = r0.bjd;
        r4.clear();
        r0 = r24;
        r4 = r0.length;
        r14 = new com.google.android.exoplayer2.source.l[r4];
        r0 = r24;
        r4 = r0.length;
        r15 = new com.google.android.exoplayer2.source.l[r4];
        r0 = r24;
        r4 = r0.length;
        r0 = new com.google.android.exoplayer2.g.f[r4];
        r16 = r0;
        r6 = 0;
        r0 = r23;
        r4 = r0.bjg;
        r4 = r4.length;
        r0 = new com.google.android.exoplayer2.source.b.j[r4];
        r17 = r0;
        r4 = 0;
        r5 = r4;
    L_0x0081:
        r0 = r23;
        r4 = r0.bjg;
        r4 = r4.length;
        if (r5 >= r4) goto L_0x0275;
    L_0x0088:
        r4 = 0;
    L_0x0089:
        r0 = r24;
        r8 = r0.length;
        if (r4 >= r8) goto L_0x00a5;
    L_0x008e:
        r8 = r12[r4];
        if (r8 != r5) goto L_0x00a1;
    L_0x0092:
        r8 = r26[r4];
    L_0x0094:
        r15[r4] = r8;
        r8 = r13[r4];
        if (r8 != r5) goto L_0x00a3;
    L_0x009a:
        r8 = r24[r4];
    L_0x009c:
        r16[r4] = r8;
        r4 = r4 + 1;
        goto L_0x0089;
    L_0x00a1:
        r8 = 0;
        goto L_0x0094;
    L_0x00a3:
        r8 = 0;
        goto L_0x009c;
    L_0x00a5:
        r0 = r23;
        r4 = r0.bjg;
        r18 = r4[r5];
        r0 = r18;
        r4 = r0.prepared;
        com.google.android.exoplayer2.i.a.checkState(r4);
        r0 = r18;
        r9 = r0.bgT;
        r4 = 0;
        r8 = r4;
    L_0x00b8:
        r0 = r16;
        r4 = r0.length;
        if (r8 >= r4) goto L_0x00dc;
    L_0x00bd:
        r4 = r15[r8];
        if (r4 == 0) goto L_0x00d8;
    L_0x00c1:
        r4 = r16[r8];
        if (r4 == 0) goto L_0x00c9;
    L_0x00c5:
        r4 = r25[r8];
        if (r4 != 0) goto L_0x00d8;
    L_0x00c9:
        r4 = r15[r8];
        r4 = (com.google.android.exoplayer2.source.b.i) r4;
        r4 = r4.bjl;
        r10 = 0;
        r0 = r18;
        r0.r(r4, r10);
        r4 = 0;
        r15[r8] = r4;
    L_0x00d8:
        r4 = r8 + 1;
        r8 = r4;
        goto L_0x00b8;
    L_0x00dc:
        if (r7 != 0) goto L_0x00e6;
    L_0x00de:
        r0 = r18;
        r4 = r0.bgR;
        if (r4 == 0) goto L_0x0154;
    L_0x00e4:
        if (r9 != 0) goto L_0x015c;
    L_0x00e6:
        r4 = 1;
    L_0x00e7:
        r0 = r18;
        r8 = r0.bjo;
        r11 = r8.biB;
        r9 = 0;
        r8 = r4;
        r10 = r11;
    L_0x00f0:
        r0 = r16;
        r4 = r0.length;
        if (r9 >= r4) goto L_0x0160;
    L_0x00f5:
        r4 = r15[r9];
        if (r4 != 0) goto L_0x02a3;
    L_0x00f9:
        r4 = r16[r9];
        if (r4 == 0) goto L_0x02a3;
    L_0x00fd:
        r4 = r16[r9];
        r0 = r18;
        r0 = r0.aNe;
        r19 = r0;
        r20 = r4.tf();
        r19 = r19.a(r20);
        r20 = 1;
        r18.r(r19, r20);
        r0 = r18;
        r0 = r0.bju;
        r20 = r0;
        r0 = r19;
        r1 = r20;
        if (r0 != r1) goto L_0x0125;
    L_0x011e:
        r0 = r18;
        r10 = r0.bjo;
        r10.biB = r4;
        r10 = r4;
    L_0x0125:
        r4 = new com.google.android.exoplayer2.source.b.i;
        r0 = r18;
        r1 = r19;
        r4.<init>(r0, r1);
        r15[r9] = r4;
        r4 = 1;
        r27[r9] = r4;
        if (r8 != 0) goto L_0x02a3;
    L_0x0135:
        r0 = r18;
        r4 = r0.bgO;
        r4 = r4[r19];
        r4.rewind();
        r8 = 1;
        r0 = r28;
        r8 = r4.g(r0, r8);
        if (r8 != 0) goto L_0x015e;
    L_0x0147:
        r4 = r4.bhG;
        r4 = r4.sj();
        if (r4 == 0) goto L_0x015e;
    L_0x014f:
        r4 = 1;
    L_0x0150:
        r9 = r9 + 1;
        r8 = r4;
        goto L_0x00f0;
    L_0x0154:
        r0 = r18;
        r8 = r0.bgZ;
        r4 = (r28 > r8 ? 1 : (r28 == r8 ? 0 : -1));
        if (r4 != 0) goto L_0x00e6;
    L_0x015c:
        r4 = 0;
        goto L_0x00e7;
    L_0x015e:
        r4 = 0;
        goto L_0x0150;
    L_0x0160:
        r0 = r18;
        r4 = r0.bgT;
        if (r4 != 0) goto L_0x01cd;
    L_0x0166:
        r0 = r18;
        r4 = r0.bjo;
        r9 = 0;
        r4.biw = r9;
        r4 = 0;
        r0 = r18;
        r0.bjs = r4;
        r0 = r18;
        r4 = r0.bjr;
        r4.clear();
        r0 = r18;
        r4 = r0.bgI;
        r4 = r4.isLoading();
        if (r4 == 0) goto L_0x01c9;
    L_0x0183:
        r0 = r18;
        r9 = r0.bgO;
        r10 = r9.length;
        r4 = 0;
    L_0x0189:
        if (r4 >= r10) goto L_0x0193;
    L_0x018b:
        r11 = r9[r4];
        r11.sq();
        r4 = r4 + 1;
        goto L_0x0189;
    L_0x0193:
        r0 = r18;
        r4 = r0.bgI;
        r4.cancelLoading();
    L_0x019a:
        r4 = 1;
        r0 = r18;
        r0.bgR = r4;
        r4 = 0;
        r9 = 0;
    L_0x01a1:
        r0 = r24;
        r10 = r0.length;
        if (r9 >= r10) goto L_0x023b;
    L_0x01a6:
        r10 = r13[r9];
        if (r10 != r5) goto L_0x022c;
    L_0x01aa:
        r4 = r15[r9];
        if (r4 == 0) goto L_0x022a;
    L_0x01ae:
        r4 = 1;
    L_0x01af:
        com.google.android.exoplayer2.i.a.checkState(r4);
        r4 = r15[r9];
        r14[r9] = r4;
        r4 = 1;
        r0 = r23;
        r10 = r0.bjd;
        r11 = r15[r9];
        r19 = java.lang.Integer.valueOf(r5);
        r0 = r19;
        r10.put(r11, r0);
    L_0x01c6:
        r9 = r9 + 1;
        goto L_0x01a1;
    L_0x01c9:
        r18.sA();
        goto L_0x019a;
    L_0x01cd:
        r0 = r18;
        r4 = r0.bjr;
        r4 = r4.isEmpty();
        if (r4 != 0) goto L_0x029d;
    L_0x01d7:
        r4 = com.google.android.exoplayer2.i.v.j(r10, r11);
        if (r4 != 0) goto L_0x029d;
    L_0x01dd:
        r9 = 0;
        r0 = r18;
        r4 = r0.bgR;
        if (r4 != 0) goto L_0x0228;
    L_0x01e4:
        r20 = 0;
        r0 = r20;
        r10.ag(r0);
        r0 = r18;
        r4 = r0.bjo;
        r11 = r4.bis;
        r0 = r18;
        r4 = r0.bjr;
        r4 = r4.getLast();
        r4 = (com.google.android.exoplayer2.source.b.f) r4;
        r4 = r4.bic;
        r4 = r11.j(r4);
        r10 = r10.th();
        if (r10 == r4) goto L_0x02a0;
    L_0x0207:
        r4 = 1;
    L_0x0208:
        if (r4 == 0) goto L_0x029d;
    L_0x020a:
        r4 = 1;
        r8 = 1;
        r9 = 1;
        r0 = r18;
        r0.bjy = r9;
    L_0x0211:
        if (r8 == 0) goto L_0x019a;
    L_0x0213:
        r0 = r18;
        r1 = r28;
        r0.j(r1, r4);
        r4 = 0;
    L_0x021b:
        r9 = r15.length;
        if (r4 >= r9) goto L_0x019a;
    L_0x021e:
        r9 = r15[r4];
        if (r9 == 0) goto L_0x0225;
    L_0x0222:
        r9 = 1;
        r27[r4] = r9;
    L_0x0225:
        r4 = r4 + 1;
        goto L_0x021b;
    L_0x0228:
        r4 = 1;
        goto L_0x0208;
    L_0x022a:
        r4 = 0;
        goto L_0x01af;
    L_0x022c:
        r10 = r12[r9];
        if (r10 != r5) goto L_0x01c6;
    L_0x0230:
        r10 = r15[r9];
        if (r10 != 0) goto L_0x0239;
    L_0x0234:
        r10 = 1;
    L_0x0235:
        com.google.android.exoplayer2.i.a.checkState(r10);
        goto L_0x01c6;
    L_0x0239:
        r10 = 0;
        goto L_0x0235;
    L_0x023b:
        if (r4 == 0) goto L_0x0268;
    L_0x023d:
        r17[r6] = r18;
        r4 = r6 + 1;
        if (r6 != 0) goto L_0x026d;
    L_0x0243:
        r6 = 1;
        r0 = r18;
        r0.aJ(r6);
        if (r8 != 0) goto L_0x025d;
    L_0x024b:
        r0 = r23;
        r6 = r0.bjh;
        r6 = r6.length;
        if (r6 == 0) goto L_0x025d;
    L_0x0252:
        r0 = r23;
        r6 = r0.bjh;
        r8 = 0;
        r6 = r6[r8];
        r0 = r18;
        if (r0 == r6) goto L_0x0273;
    L_0x025d:
        r0 = r23;
        r6 = r0.bip;
        r6 = r6.bjA;
        r6.clear();
        r7 = 1;
        r6 = r4;
    L_0x0268:
        r4 = r5 + 1;
        r5 = r4;
        goto L_0x0081;
    L_0x026d:
        r6 = 0;
        r0 = r18;
        r0.aJ(r6);
    L_0x0273:
        r6 = r4;
        goto L_0x0268;
    L_0x0275:
        r4 = 0;
        r5 = 0;
        r7 = r14.length;
        r0 = r26;
        java.lang.System.arraycopy(r14, r4, r0, r5, r7);
        r0 = r17;
        r4 = java.util.Arrays.copyOf(r0, r6);
        r4 = (com.google.android.exoplayer2.source.b.j[]) r4;
        r0 = r23;
        r0.bjh = r4;
        r4 = new com.google.android.exoplayer2.source.e;
        r0 = r23;
        r5 = r0.bjh;
        r4.<init>(r5);
        r0 = r23;
        r0.bji = r4;
        r4 = 125913; // 0x1ebd9 float:1.76442E-40 double:6.22093E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r4);
        return r28;
    L_0x029d:
        r4 = r7;
        goto L_0x0211;
    L_0x02a0:
        r4 = r9;
        goto L_0x0208;
    L_0x02a3:
        r4 = r8;
        goto L_0x0150;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.google.android.exoplayer2.source.b.g.a(com.google.android.exoplayer2.g.f[], boolean[], com.google.android.exoplayer2.source.l[], boolean[], long):long");
    }

    public final void W(long j) {
        AppMethodBeat.i(125914);
        for (j jVar : this.bjh) {
            int length = jVar.bgO.length;
            for (int i = 0; i < length; i++) {
                jVar.bgO[i].i(j, jVar.bjw[i]);
            }
        }
        AppMethodBeat.o(125914);
    }

    public final boolean Y(long j) {
        AppMethodBeat.i(125915);
        boolean Y = this.bji.Y(j);
        AppMethodBeat.o(125915);
        return Y;
    }

    public final long rV() {
        AppMethodBeat.i(125916);
        long rV = this.bji.rV();
        AppMethodBeat.o(125916);
        return rV;
    }

    public final long rT() {
        return -9223372036854775807L;
    }

    public final long rU() {
        AppMethodBeat.i(125917);
        long rU = this.bji.rU();
        AppMethodBeat.o(125917);
        return rU;
    }

    public final long X(long j) {
        AppMethodBeat.i(125918);
        if (this.bjh.length > 0) {
            boolean j2 = this.bjh[0].j(j, false);
            for (int i = 1; i < this.bjh.length; i++) {
                this.bjh[i].j(j, j2);
            }
            if (j2) {
                this.bip.bjA.clear();
            }
        }
        AppMethodBeat.o(125918);
        return j;
    }

    public final void pL() {
        AppMethodBeat.i(125919);
        int i = this.bjf - 1;
        this.bjf = i;
        if (i > 0) {
            AppMethodBeat.o(125919);
            return;
        }
        int i2 = 0;
        for (j jVar : this.bjg) {
            i2 += jVar.aNe.length;
        }
        o[] oVarArr = new o[i2];
        i2 = 0;
        for (j jVar2 : this.bjg) {
            int i3 = jVar2.aNe.length;
            i = 0;
            while (i < i3) {
                int i4 = i2 + 1;
                oVarArr[i2] = jVar2.aNe.bia[i];
                i++;
                i2 = i4;
            }
        }
        this.aNe = new p(oVarArr);
        this.bgq.a(this);
        AppMethodBeat.o(125919);
    }

    public final void a(com.google.android.exoplayer2.source.b.a.a.a aVar) {
        AppMethodBeat.i(125920);
        ((e.a) this.bir.bkC.get(aVar)).sD();
        AppMethodBeat.o(125920);
    }

    public final void sx() {
        AppMethodBeat.i(125921);
        sy();
        AppMethodBeat.o(125921);
    }

    public final void b(com.google.android.exoplayer2.source.b.a.a.a aVar) {
        AppMethodBeat.i(125922);
        for (j jVar : this.bjg) {
            c cVar = jVar.bjo;
            int j = cVar.bis.j(aVar.aOv);
            if (j != -1) {
                j = cVar.biB.indexOf(j);
                if (j != -1) {
                    cVar.biB.eI(j);
                }
            }
        }
        sy();
        AppMethodBeat.o(125922);
    }

    private j a(int i, com.google.android.exoplayer2.source.b.a.a.a[] aVarArr, Format format, List<Format> list, long j) {
        AppMethodBeat.i(125923);
        c cVar = new c(this.bir, aVarArr, this.bjb, this.bip, list);
        j jVar = new j(i, this, cVar, this.bgF, j, format, this.bgC, this.bjc);
        AppMethodBeat.o(125923);
        return jVar;
    }

    private void sy() {
        AppMethodBeat.i(125924);
        if (this.aNe != null) {
            this.bgq.a(this);
            AppMethodBeat.o(125924);
            return;
        }
        for (j sz : this.bjg) {
            sz.sz();
        }
        AppMethodBeat.o(125924);
    }

    private static boolean a(com.google.android.exoplayer2.source.b.a.a.a aVar, String str) {
        AppMethodBeat.i(125925);
        String str2 = aVar.aOv.aOa;
        if (TextUtils.isEmpty(str2)) {
            AppMethodBeat.o(125925);
            return false;
        }
        for (String startsWith : str2.split("(\\s*,\\s*)|(\\s*$)")) {
            if (startsWith.startsWith(str)) {
                AppMethodBeat.o(125925);
                return true;
            }
        }
        AppMethodBeat.o(125925);
        return false;
    }
}
