package V0;

import C3.A;
import C3.AbstractC0055q;
import C3.G;
import C3.W;
import d5.AbstractC0844a;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import u0.C1578n;
import u0.C1579o;
import u0.E;
import x0.AbstractC1709a;
import x0.o;
import x0.v;

/* JADX INFO: loaded from: classes.dex */
public final class f implements a {

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

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

    public f(int i, W w4) {
        this.f6848b = i;
        this.f6847a = w4;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    public static f c(int i, o oVar) {
        a gVar;
        String str;
        int i5 = 4;
        AbstractC0055q.c(4, "initialCapacity");
        Object[] objArrCopyOf = new Object[4];
        int i8 = oVar.f18541c;
        int iB = -2;
        int i9 = 0;
        while (oVar.a() > 8) {
            int i10 = oVar.i();
            int i11 = oVar.f18540b + oVar.i();
            oVar.E(i11);
            if (i10 != 1414744396) {
                d dVar = null;
                switch (i10) {
                    case 1718776947:
                        if (iB != 2) {
                            if (iB == 1) {
                                int iM = oVar.m();
                                String str2 = iM != 1 ? iM != 85 ? iM != 255 ? iM != 8192 ? iM != 8193 ? null : "audio/vnd.dts" : "audio/ac3" : "audio/mp4a-latm" : "audio/mpeg" : "audio/raw";
                                if (str2 != null) {
                                    int iM2 = oVar.m();
                                    int i12 = oVar.i();
                                    oVar.G(6);
                                    int iY = v.y(oVar.m());
                                    int iM3 = oVar.a() > 0 ? oVar.m() : 0;
                                    C1578n c1578n = new C1578n();
                                    c1578n.f17320m = E.m(str2);
                                    c1578n.f17301C = iM2;
                                    c1578n.D = i12;
                                    if (str2.equals("audio/raw") && iY != 0) {
                                        c1578n.f17302E = iY;
                                    }
                                    if (str2.equals("audio/mp4a-latm") && iM3 > 0) {
                                        byte[] bArr = new byte[iM3];
                                        oVar.e(bArr, 0, iM3);
                                        c1578n.f17323p = G.p(bArr);
                                    }
                                    gVar = new g(new C1579o(c1578n));
                                } else {
                                    AbstractC0844a.s(iM, "Ignoring track with unsupported format tag ", "StreamFormatChunk");
                                }
                            } else {
                                AbstractC1709a.B("StreamFormatChunk", "Ignoring strf box for unsupported track type: " + v.C(iB));
                            }
                            gVar = dVar;
                            break;
                        } else {
                            oVar.G(i5);
                            int i13 = oVar.i();
                            int i14 = oVar.i();
                            oVar.G(i5);
                            int i15 = oVar.i();
                            switch (i15) {
                                case 808802372:
                                case 877677894:
                                case 1145656883:
                                case 1145656920:
                                case 1482049860:
                                case 1684633208:
                                case 2021026148:
                                    str = "video/mp4v-es";
                                    break;
                                case 826496577:
                                case 828601953:
                                case 875967048:
                                    str = "video/avc";
                                    break;
                                case 842289229:
                                    str = "video/mp42";
                                    break;
                                case 859066445:
                                    str = "video/mp43";
                                    break;
                                case 1196444237:
                                case 1735420525:
                                    str = "video/mjpeg";
                                    break;
                                default:
                                    str = null;
                                    break;
                            }
                            if (str != null) {
                                C1578n c1578n2 = new C1578n();
                                c1578n2.f17327t = i13;
                                c1578n2.f17328u = i14;
                                c1578n2.f17320m = E.m(str);
                                gVar = new g(new C1579o(c1578n2));
                            } else {
                                AbstractC0844a.s(i15, "Ignoring track with unsupported compression ", "StreamFormatChunk");
                                gVar = dVar;
                            }
                        }
                        break;
                    case 1751742049:
                        int i16 = oVar.i();
                        oVar.G(8);
                        int i17 = oVar.i();
                        int i18 = oVar.i();
                        oVar.G(i5);
                        oVar.i();
                        oVar.G(12);
                        gVar = new c(i16, i17, i18);
                        break;
                    case 1752331379:
                        int i19 = oVar.i();
                        oVar.G(12);
                        oVar.i();
                        int i20 = oVar.i();
                        int i21 = oVar.i();
                        oVar.G(i5);
                        int i22 = oVar.i();
                        int i23 = oVar.i();
                        oVar.G(i5);
                        dVar = new d(i19, i20, i21, i22, i23, oVar.i());
                        gVar = dVar;
                        break;
                    case 1852994675:
                        gVar = new h(oVar.r(oVar.a(), StandardCharsets.UTF_8));
                        break;
                    default:
                        gVar = dVar;
                        break;
                }
            } else {
                gVar = c(oVar.i(), oVar);
            }
            if (gVar != null) {
                if (gVar.a() == 1752331379) {
                    iB = ((d) gVar).b();
                }
                int i24 = i9 + 1;
                int iF = A.f(objArrCopyOf.length, i24);
                if (iF > objArrCopyOf.length) {
                    objArrCopyOf = Arrays.copyOf(objArrCopyOf, iF);
                }
                objArrCopyOf[i9] = gVar;
                i9 = i24;
            }
            oVar.F(i11);
            oVar.E(i8);
            i5 = 4;
        }
        return new f(i, G.i(i9, objArrCopyOf));
    }

    @Override // V0.a
    public final int a() {
        return this.f6848b;
    }

    public final a b(Class cls) {
        C3.E eListIterator = this.f6847a.listIterator(0);
        while (eListIterator.hasNext()) {
            a aVar = (a) eListIterator.next();
            if (aVar.getClass() == cls) {
                return aVar;
            }
        }
        return null;
    }
}
