package r;

import a0.y;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.util.Pair;
import androidx.exifinterface.media.ExifInterface;
import b0.AbstractC0399d;
import b0.C;
import b0.D;
import b0.u;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import n.z;
import org.xml.sax.helpers.DefaultHandler;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import r.k;
import u.InterfaceC0722a;

/* JADX INFO: loaded from: classes.dex */
public class e extends DefaultHandler implements y.a {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final Pattern f6299f = Pattern.compile("(\\d+)(?:/(\\d+))?");

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private final byte[] f6302c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private HashMap f6303d = new HashMap();

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

    protected static final class a implements Comparator {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        private ArrayList f6305b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private ArrayList f6306g;

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

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

        protected a() {
        }

        private void e(List list, C0699b c0699b) {
            if (list.contains(c0699b)) {
                return;
            }
            for (int i2 = 0; i2 < list.size(); i2++) {
                AbstractC0399d.e(!((C0699b) list.get(i2)).f6284a.equals(c0699b.f6284a));
            }
            list.add(c0699b);
        }

        public void a(C0699b c0699b) {
            if (this.f6305b == null) {
                this.f6305b = new ArrayList();
            }
            e(this.f6305b, c0699b);
        }

        public ArrayList b() {
            ArrayList arrayList = this.f6305b;
            if (arrayList == null) {
                return this.f6306g;
            }
            if (this.f6306g == null) {
                return arrayList;
            }
            for (int i2 = 0; i2 < this.f6306g.size(); i2++) {
                e(this.f6305b, (C0699b) this.f6306g.get(i2));
            }
            return this.f6305b;
        }

        @Override // java.util.Comparator
        /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
        public int compare(C0699b c0699b, C0699b c0699b2) {
            return c0699b.f6284a.compareTo(c0699b2.f6284a);
        }

        public void d() {
            if (this.f6308x) {
                ArrayList arrayList = this.f6307r;
                if (arrayList == null) {
                    AbstractC0399d.e(this.f6306g == null);
                } else {
                    Collections.sort(arrayList, this);
                    AbstractC0399d.e(this.f6307r.equals(this.f6306g));
                }
            } else {
                ArrayList arrayList2 = this.f6307r;
                if (arrayList2 != null) {
                    Collections.sort(arrayList2, this);
                }
                this.f6306g = this.f6307r;
                this.f6308x = true;
            }
            this.f6307r = null;
        }
    }

    public e(String str, byte[] bArr) {
        this.f6300a = str;
        this.f6302c = bArr;
        try {
            this.f6301b = XmlPullParserFactory.newInstance();
        } catch (XmlPullParserException e2) {
            throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e2);
        }
    }

    protected static float A(XmlPullParser xmlPullParser, float f2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, "frameRate");
        if (attributeValue == null) {
            return f2;
        }
        Matcher matcher = f6299f.matcher(attributeValue);
        if (!matcher.matches()) {
            return f2;
        }
        int i2 = Integer.parseInt(matcher.group(1));
        return !TextUtils.isEmpty(matcher.group(2)) ? i2 / Integer.parseInt(r2) : i2;
    }

    protected static int C(XmlPullParser xmlPullParser, String str) {
        return D(xmlPullParser, str, -1);
    }

    protected static int D(XmlPullParser xmlPullParser, String str, int i2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue == null ? i2 : Integer.parseInt(attributeValue);
    }

    protected static long E(XmlPullParser xmlPullParser, String str) {
        return F(xmlPullParser, str, -1L);
    }

    protected static long F(XmlPullParser xmlPullParser, String str, long j2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue == null ? j2 : Long.parseLong(attributeValue);
    }

    protected static String P(XmlPullParser xmlPullParser, String str, String str2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue == null ? str2 : attributeValue;
    }

    private static int n(int i2, int i3) {
        if (i2 == -1) {
            return i3;
        }
        if (i3 == -1) {
            return i2;
        }
        AbstractC0399d.e(i2 == i3);
        return i2;
    }

    private static String o(String str, String str2) {
        if (str == null) {
            return str2;
        }
        if (str2 == null) {
            return str;
        }
        AbstractC0399d.e(str.equals(str2));
        return str;
    }

    protected static String v(XmlPullParser xmlPullParser, String str) throws XmlPullParserException, IOException {
        xmlPullParser.next();
        return C.c(str, xmlPullParser.getText());
    }

    protected static long y(XmlPullParser xmlPullParser, String str, long j2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue == null ? j2 : D.G(attributeValue);
    }

    protected static long z(XmlPullParser xmlPullParser, String str, long j2) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue == null ? j2 : D.H(attributeValue);
    }

    protected g B(XmlPullParser xmlPullParser) {
        return I(xmlPullParser, "sourceURL", "range");
    }

    protected C0701d G(XmlPullParser xmlPullParser, String str) throws XmlPullParserException, IOException {
        long j2;
        long j3;
        String str2;
        long j4;
        m mVarR;
        e eVar = this;
        long jY = y(xmlPullParser, "availabilityStartTime", -1L);
        long jZ = z(xmlPullParser, "mediaPresentationDuration", -1L);
        eVar.f6304e = jZ;
        long jZ2 = z(xmlPullParser, "minBufferTime", -1L);
        String attributeValue = xmlPullParser.getAttributeValue(null, "type");
        String attributeValue2 = xmlPullParser.getAttributeValue(null, "profiles");
        boolean zEquals = attributeValue != null ? attributeValue.equals("dynamic") : false;
        long jZ3 = zEquals ? z(xmlPullParser, "minimumUpdatePeriod", -1L) : -1L;
        long jZ4 = zEquals ? z(xmlPullParser, "timeShiftBufferDepth", -1L) : -1L;
        ArrayList arrayList = new ArrayList();
        boolean z2 = false;
        boolean z3 = false;
        long j5 = zEquals ? -1L : 0L;
        m mVar = null;
        String strNextText = null;
        boolean z4 = false;
        String strV = str;
        while (true) {
            xmlPullParser.next();
            m mVar2 = mVar;
            if (u.e(xmlPullParser, "BaseURL")) {
                if (!z4) {
                    strV = v(xmlPullParser, strV);
                    j3 = jZ3;
                    z4 = true;
                    mVarR = mVar2;
                }
                j2 = j5;
                j3 = jZ3;
                mVarR = mVar2;
                strV = strV;
                j5 = j2;
            } else {
                if (u.e(xmlPullParser, "UTCTiming")) {
                    if (!z2) {
                        j3 = jZ3;
                        z2 = true;
                        mVarR = R(xmlPullParser);
                    }
                    j2 = j5;
                    j3 = jZ3;
                    mVarR = mVar2;
                    strV = strV;
                } else if (u.e(xmlPullParser, "Location")) {
                    strNextText = xmlPullParser.nextText();
                    j3 = jZ3;
                    mVarR = mVar2;
                } else if (!u.e(xmlPullParser, "Period") || z3) {
                    j2 = j5;
                    j3 = jZ3;
                    mVarR = mVar2;
                    strV = strV;
                } else {
                    Pair pairH = eVar.H(xmlPullParser, strV, j5);
                    j2 = j5;
                    f fVar = (f) pairH.first;
                    j3 = jZ3;
                    if (fVar.f6310b != -1) {
                        long jLongValue = ((Long) pairH.second).longValue();
                        if (jLongValue == -1) {
                            str2 = strV;
                            j4 = -1;
                        } else {
                            str2 = strV;
                            j4 = fVar.f6310b + jLongValue;
                        }
                        arrayList.add(fVar);
                        mVarR = mVar2;
                        long j6 = j4;
                        strV = str2;
                        j5 = j6;
                    } else {
                        if (!zEquals) {
                            throw new z("Unable to determine start of period " + arrayList.size());
                        }
                        mVarR = mVar2;
                        z3 = true;
                    }
                }
                j5 = j2;
            }
            if (u.c(xmlPullParser, "MPD")) {
                if (jZ == -1) {
                    if (j5 != -1) {
                        jZ = j5;
                    } else if (!zEquals) {
                        throw new z("Unable to determine duration of static manifest.");
                    }
                }
                if (arrayList.isEmpty()) {
                    throw new z("No periods found.");
                }
                return e(jY, jZ, jZ2, zEquals, j3, jZ4, mVarR, strNextText, arrayList, attributeValue2);
            }
            eVar = this;
            mVar = mVarR;
            jZ3 = j3;
        }
    }

    protected Pair H(XmlPullParser xmlPullParser, String str, long j2) throws XmlPullParserException, IOException {
        String attributeValue = xmlPullParser.getAttributeValue(null, "id");
        long jZ = z(xmlPullParser, "start", j2);
        long jZ2 = z(xmlPullParser, "duration", -1L);
        ArrayList arrayList = new ArrayList();
        boolean z2 = false;
        k kVarM = null;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, "BaseURL")) {
                if (!z2) {
                    str = v(xmlPullParser, str);
                    z2 = true;
                }
            } else if (u.e(xmlPullParser, "AdaptationSet")) {
                arrayList.add(s(xmlPullParser, str, kVarM));
            } else if (u.e(xmlPullParser, "SegmentBase")) {
                kVarM = K(xmlPullParser, null);
            } else if (u.e(xmlPullParser, "SegmentList")) {
                kVarM = L(xmlPullParser, null);
            } else if (u.e(xmlPullParser, "SegmentTemplate")) {
                kVarM = M(xmlPullParser, null);
            }
        } while (!u.c(xmlPullParser, "Period"));
        return Pair.create(f(attributeValue, jZ, arrayList), Long.valueOf(jZ2));
    }

    protected g I(XmlPullParser xmlPullParser, String str, String str2) {
        long j2;
        long j3;
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        String attributeValue2 = xmlPullParser.getAttributeValue(null, str2);
        if (attributeValue2 != null) {
            String[] strArrSplit = attributeValue2.split("-");
            j2 = Long.parseLong(strArrSplit[0]);
            if (strArrSplit.length == 2) {
                j3 = (Long.parseLong(strArrSplit[1]) - j2) + 1;
            }
            return g(attributeValue, j2, j3);
        }
        j2 = 0;
        j3 = -1;
        return g(attributeValue, j2, j3);
    }

    /* JADX WARN: Removed duplicated region for block: B:38:0x0114 A[LOOP:0: B:3:0x0048->B:38:0x0114, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00b7 A[EDGE_INSN: B:39:0x00b7->B:28:0x00b7 BREAK  A[LOOP:0: B:3:0x0048->B:38:0x0114], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    protected r.h J(org.xmlpull.v1.XmlPullParser r23, java.lang.String r24, java.lang.String r25, java.lang.String r26, int r27, int r28, float r29, int r30, int r31, java.lang.String r32, r.k r33, r.e.a r34) throws org.xmlpull.v1.XmlPullParserException, java.io.IOException {
        /*
            Method dump skipped, instruction units count: 282
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: r.e.J(org.xmlpull.v1.XmlPullParser, java.lang.String, java.lang.String, java.lang.String, int, int, float, int, int, java.lang.String, r.k, r.e$a):r.h");
    }

    protected k.e K(XmlPullParser xmlPullParser, k.e eVar) throws XmlPullParserException, IOException {
        long j2;
        long jF = F(xmlPullParser, "timescale", eVar != null ? eVar.f6331b : 1L);
        long jF2 = F(xmlPullParser, "presentationTimeOffset", eVar != null ? eVar.f6332c : 0L);
        long j3 = eVar != null ? eVar.f6341d : 0L;
        long j4 = eVar != null ? eVar.f6342e : -1L;
        String attributeValue = xmlPullParser.getAttributeValue(null, "indexRange");
        if (attributeValue != null) {
            String[] strArrSplit = attributeValue.split("-");
            long j5 = Long.parseLong(strArrSplit[0]);
            long j6 = (Long.parseLong(strArrSplit[1]) - j5) + 1;
            j3 = j5;
            j2 = j6;
        } else {
            j2 = j4;
        }
        g gVarB = eVar != null ? eVar.f6330a : null;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, "Initialization")) {
                gVarB = B(xmlPullParser);
            }
        } while (!u.c(xmlPullParser, "SegmentBase"));
        return l(gVarB == null ? g(null, 0L, j3) : gVarB, jF, jF2, j3, j2);
    }

    protected k.b L(XmlPullParser xmlPullParser, k.b bVar) throws XmlPullParserException, IOException {
        long jF = F(xmlPullParser, "timescale", bVar != null ? bVar.f6331b : 1L);
        long jF2 = F(xmlPullParser, "presentationTimeOffset", bVar != null ? bVar.f6332c : 0L);
        long jF3 = F(xmlPullParser, "duration", bVar != null ? bVar.f6334e : -1L);
        int iD = D(xmlPullParser, "startNumber", bVar != null ? bVar.f6333d : 1);
        List arrayList = null;
        g gVarB = null;
        List listN = null;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, "Initialization")) {
                gVarB = B(xmlPullParser);
            } else if (u.e(xmlPullParser, "SegmentTimeline")) {
                listN = N(xmlPullParser, jF);
            } else if (u.e(xmlPullParser, "SegmentURL")) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(O(xmlPullParser));
            }
        } while (!u.c(xmlPullParser, "SegmentList"));
        if (bVar != null) {
            if (gVarB == null) {
                gVarB = bVar.f6330a;
            }
            if (listN == null) {
                listN = bVar.f6335f;
            }
            if (arrayList == null) {
                arrayList = bVar.f6336g;
            }
        }
        return i(gVarB, jF, jF2, iD, jF3, listN, arrayList);
    }

    protected k.c M(XmlPullParser xmlPullParser, k.c cVar) throws XmlPullParserException, IOException {
        long jF = F(xmlPullParser, "timescale", cVar != null ? cVar.f6331b : 1L);
        long jF2 = F(xmlPullParser, "presentationTimeOffset", cVar != null ? cVar.f6332c : 0L);
        long jF3 = F(xmlPullParser, "duration", cVar != null ? cVar.f6334e : -1L);
        int iD = D(xmlPullParser, "startNumber", cVar != null ? cVar.f6333d : 1);
        g gVarB = null;
        l lVarQ = Q(xmlPullParser, "media", cVar != null ? cVar.f6338h : null);
        l lVarQ2 = Q(xmlPullParser, "initialization", cVar != null ? cVar.f6337g : null);
        List listN = null;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, "Initialization")) {
                gVarB = B(xmlPullParser);
            } else if (u.e(xmlPullParser, "SegmentTimeline")) {
                listN = N(xmlPullParser, jF);
            }
        } while (!u.c(xmlPullParser, "SegmentTemplate"));
        if (cVar != null) {
            if (gVarB == null) {
                gVarB = cVar.f6330a;
            }
            if (listN == null) {
                listN = cVar.f6335f;
            }
        }
        return j(gVarB, jF, jF2, iD, jF3, listN, lVarQ2, lVarQ);
    }

    protected List N(XmlPullParser xmlPullParser, long j2) throws XmlPullParserException, IOException {
        ArrayList arrayList = new ArrayList();
        long jF = 0;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, ExifInterface.LATITUDE_SOUTH)) {
                jF = F(xmlPullParser, "t", jF);
                long jE = E(xmlPullParser, "d");
                int iRound = D(xmlPullParser, "r", 0) < 0 ? Math.round((this.f6304e / Math.round(jE / j2)) / 1000.0f) : D(xmlPullParser, "r", 0) + 1;
                for (int i2 = 0; i2 < iRound; i2++) {
                    arrayList.add(k(jF, jE));
                    jF += jE;
                }
            }
        } while (!u.c(xmlPullParser, "SegmentTimeline"));
        return arrayList;
    }

    protected g O(XmlPullParser xmlPullParser) {
        return I(xmlPullParser, "media", "mediaRange");
    }

    protected l Q(XmlPullParser xmlPullParser, String str, l lVar) {
        String attributeValue = xmlPullParser.getAttributeValue(null, str);
        return attributeValue != null ? l.b(attributeValue) : lVar;
    }

    protected m R(XmlPullParser xmlPullParser) {
        return m(xmlPullParser.getAttributeValue(null, "schemeIdUri"), xmlPullParser.getAttributeValue(null, "value"));
    }

    protected C0698a b(int i2, int i3, List list, List list2, List list3, String str) {
        return new C0698a(i2, i3, list, list2, list3, str);
    }

    protected C0699b c(String str, UUID uuid, InterfaceC0722a.b bVar) {
        return new C0699b(str, uuid, bVar);
    }

    protected p.j d(String str, String str2, int i2, int i3, float f2, int i4, int i5, int i6, String str3, String str4) {
        return new p.j(str, str2, i2, i3, f2, i4, i5, i6, str3, str4);
    }

    protected C0701d e(long j2, long j3, long j4, boolean z2, long j5, long j6, m mVar, String str, List list, String str2) {
        return new C0701d(j2, j3, j4, z2, j5, j6, mVar, str, list, str2, this.f6303d);
    }

    protected f f(String str, long j2, List list) {
        return new f(str, j2, list);
    }

    public final void finalize() {
    }

    protected g g(String str, long j2, long j3) {
        return new g(str, j2, j3);
    }

    protected h h(String str, int i2, p.j jVar, k kVar, String str2) {
        return h.m(str, i2, jVar, str2, kVar, null);
    }

    protected k.b i(g gVar, long j2, long j3, int i2, long j4, List list, List list2) {
        return new k.b(gVar, j2, j3, i2, j4, list, list2);
    }

    protected k.c j(g gVar, long j2, long j3, int i2, long j4, List list, l lVar, l lVar2) {
        return new k.c(gVar, j2, j3, i2, j4, list, lVar, lVar2);
    }

    protected k.d k(long j2, long j3) {
        return new k.d(j2, j3);
    }

    protected k.e l(g gVar, long j2, long j3, long j4, long j5) {
        return new k.e(gVar, j2, j3, j4, j5);
    }

    protected m m(String str, String str2) {
        return new m(str, str2);
    }

    protected int p(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        if (b0.k.g(str)) {
            return 0;
        }
        if (b0.k.d(str)) {
            return 1;
        }
        if (b0.k.e(str) || "application/ttml+xml".equals(str)) {
            return 2;
        }
        "application/mp4".equals(str);
        return -1;
    }

    protected int q(h hVar) {
        String str = hVar.f6318c.f6166b;
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        if (b0.k.g(str)) {
            return 0;
        }
        if (b0.k.d(str)) {
            return 1;
        }
        if (b0.k.e(str) || "application/ttml+xml".equals(str)) {
            return 2;
        }
        if ("application/mp4".equals(str)) {
            String str2 = hVar.f6318c.f6173i;
            if ("stpp".equals(str2) || "wvtt".equals(str2)) {
                return 2;
            }
        }
        return -1;
    }

    @Override // a0.y.a
    /* JADX INFO: renamed from: r, reason: merged with bridge method [inline-methods] */
    public C0701d a(String str, InputStream inputStream) throws z {
        try {
            XmlPullParser xmlPullParserNewPullParser = this.f6301b.newPullParser();
            xmlPullParserNewPullParser.setInput(inputStream, null);
            if (xmlPullParserNewPullParser.next() == 2 && "MPD".equals(xmlPullParserNewPullParser.getName())) {
                return G(xmlPullParserNewPullParser, str);
            }
            throw new z("inputStream does not contain a valid media presentation description");
        } catch (ParseException e2) {
            throw new z(e2);
        } catch (XmlPullParserException e3) {
            throw new z(e3);
        }
    }

    protected C0698a s(XmlPullParser xmlPullParser, String str, k kVar) throws XmlPullParserException, IOException {
        String strO;
        String str2;
        a aVar;
        String str3;
        String str4;
        int i2;
        int i3;
        XmlPullParser xmlPullParser2;
        ArrayList arrayList;
        ArrayList arrayList2;
        k kVarM;
        XmlPullParser xmlPullParser3 = xmlPullParser;
        int iD = D(xmlPullParser3, "id", -1);
        int iX = x(xmlPullParser);
        String str5 = null;
        String attributeValue = xmlPullParser3.getAttributeValue(null, "mimeType");
        String attributeValue2 = xmlPullParser3.getAttributeValue(null, "codecs");
        int iD2 = D(xmlPullParser3, "width", -1);
        int iD3 = D(xmlPullParser3, "height", -1);
        float fA = A(xmlPullParser3, -1.0f);
        int iD4 = D(xmlPullParser3, "audioSamplingRate", -1);
        String str6 = "lang";
        String attributeValue3 = xmlPullParser3.getAttributeValue(null, "lang");
        a aVar2 = new a();
        ArrayList arrayList3 = new ArrayList();
        ArrayList arrayList4 = new ArrayList();
        String strV = str;
        k kVar2 = kVar;
        int iN = iX;
        int iU = -1;
        String str7 = attributeValue3;
        boolean z2 = false;
        while (true) {
            xmlPullParser.next();
            if (u.e(xmlPullParser3, "BaseURL")) {
                if (!z2) {
                    strV = v(xmlPullParser3, strV);
                    z2 = true;
                    strO = str7;
                    arrayList2 = arrayList4;
                    arrayList = arrayList3;
                    aVar = aVar2;
                    str3 = str6;
                    str4 = str5;
                    xmlPullParser2 = xmlPullParser3;
                    i2 = iD;
                }
                strO = str7;
                str2 = strV;
                arrayList2 = arrayList4;
                arrayList = arrayList3;
                aVar = aVar2;
                str3 = str6;
                str4 = str5;
                xmlPullParser2 = xmlPullParser3;
                i2 = iD;
                i3 = iN;
                iN = i3;
                strV = str2;
            } else if (u.e(xmlPullParser3, "ContentProtection")) {
                C0699b c0699bW = w(xmlPullParser);
                if (c0699bW != null) {
                    aVar2.a(c0699bW);
                }
                strO = str7;
                str2 = strV;
                arrayList2 = arrayList4;
                arrayList = arrayList3;
                aVar = aVar2;
                str3 = str6;
                str4 = str5;
                xmlPullParser2 = xmlPullParser3;
                i2 = iD;
                i3 = iN;
                iN = i3;
                strV = str2;
            } else if (u.e(xmlPullParser3, "ContentComponent")) {
                strO = o(str7, xmlPullParser3.getAttributeValue(str5, str6));
                iN = n(iN, x(xmlPullParser));
                arrayList2 = arrayList4;
                arrayList = arrayList3;
                aVar = aVar2;
                str3 = str6;
                str4 = str5;
                xmlPullParser2 = xmlPullParser3;
                i2 = iD;
            } else if (u.e(xmlPullParser3, "Representation")) {
                strO = str7;
                i2 = iD;
                ArrayList arrayList5 = arrayList3;
                aVar = aVar2;
                str3 = str6;
                str4 = str5;
                h hVarJ = J(xmlPullParser, strV, attributeValue, attributeValue2, iD2, iD3, fA, iU, iD4, strO, kVar2, aVar);
                aVar.d();
                int iN2 = n(iN, q(hVarJ));
                arrayList5.add(hVarJ);
                iN = iN2;
                arrayList = arrayList5;
                strV = strV;
                arrayList2 = arrayList4;
                xmlPullParser2 = xmlPullParser;
            } else {
                strO = str7;
                str2 = strV;
                ArrayList arrayList6 = arrayList4;
                aVar = aVar2;
                str3 = str6;
                str4 = str5;
                i2 = iD;
                i3 = iN;
                xmlPullParser2 = xmlPullParser;
                arrayList = arrayList3;
                if (u.e(xmlPullParser2, "AudioChannelConfiguration")) {
                    iU = u(xmlPullParser);
                } else {
                    if (u.e(xmlPullParser2, "SegmentBase")) {
                        kVarM = K(xmlPullParser2, (k.e) kVar2);
                    } else if (u.e(xmlPullParser2, "SegmentList")) {
                        kVarM = L(xmlPullParser2, (k.b) kVar2);
                    } else if (u.e(xmlPullParser2, "SegmentTemplate")) {
                        kVarM = M(xmlPullParser2, (k.c) kVar2);
                    } else {
                        if (u.d(xmlPullParser)) {
                            t(xmlPullParser);
                        } else {
                            if (u.e(xmlPullParser2, "Role")) {
                                arrayList2 = arrayList6;
                                arrayList2.add(new j(xmlPullParser2));
                            }
                            iN = i3;
                            strV = str2;
                        }
                        arrayList2 = arrayList6;
                        iN = i3;
                        strV = str2;
                    }
                    kVar2 = kVarM;
                }
                iN = i3;
                strV = str2;
                arrayList2 = arrayList6;
            }
            if (u.c(xmlPullParser2, "AdaptationSet")) {
                return b(i2, iN, arrayList, aVar.b(), arrayList2, strO);
            }
            xmlPullParser3 = xmlPullParser2;
            arrayList3 = arrayList;
            arrayList4 = arrayList2;
            str7 = strO;
            iD = i2;
            aVar2 = aVar;
            str6 = str3;
            str5 = str4;
        }
    }

    protected void t(XmlPullParser xmlPullParser) {
    }

    protected int u(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        int iC = "urn:mpeg:dash:23003:3:audio_channel_configuration:2011".equals(P(xmlPullParser, "schemeIdUri", null)) ? C(xmlPullParser, "value") : -1;
        do {
            xmlPullParser.next();
        } while (!u.c(xmlPullParser, "AudioChannelConfiguration"));
        return iC;
    }

    protected C0699b w(XmlPullParser xmlPullParser) throws XmlPullParserException, IOException {
        String attributeValue = xmlPullParser.getAttributeValue(null, "schemeIdUri");
        UUID uuidFromString = null;
        InterfaceC0722a.b bVar = null;
        boolean z2 = false;
        do {
            xmlPullParser.next();
            if (u.e(xmlPullParser, "cenc:pssh") && xmlPullParser.next() == 4) {
                bVar = new InterfaceC0722a.b("video/mp4", Base64.decode(xmlPullParser.getText(), 0));
                uuidFromString = y.g.d(bVar.f6518b);
                z2 = true;
            }
            if (u.e(xmlPullParser, "mspr:pro") && xmlPullParser.next() == 4) {
                bVar = new InterfaceC0722a.b("video/mp4", Base64.decode(xmlPullParser.getText(), 0));
                uuidFromString = UUID.fromString(attributeValue.substring(9));
            }
            if (u.e(xmlPullParser, "mas:MarlinContentId") && xmlPullParser.next() == 4 && !this.f6303d.containsValue(xmlPullParser.getText().trim())) {
                HashMap map = this.f6303d;
                map.put(String.valueOf(map.size()), xmlPullParser.getText().trim());
            }
        } while (!u.c(xmlPullParser, "ContentProtection"));
        byte[] bArr = this.f6302c;
        if (bArr != null) {
            bVar = new InterfaceC0722a.b("video/mp4", bArr);
            if (attributeValue.startsWith("urn:uuid:")) {
                return c(attributeValue, UUID.fromString(attributeValue.substring(9)), bVar);
            }
            byte[] bArr2 = this.f6302c;
            if (bArr2[0] == 60 && bArr2[2] == 87 && bArr2[4] == 82) {
                return c(attributeValue, u.i.f6529s, bVar);
            }
        }
        if (!z2 || uuidFromString != null) {
            return c(attributeValue, uuidFromString, bVar);
        }
        Log.w("MPDParser", "Skipped unsupported ContentProtection element");
        return null;
    }

    protected int x(XmlPullParser xmlPullParser) {
        String attributeValue = xmlPullParser.getAttributeValue(null, "contentType");
        if (TextUtils.isEmpty(attributeValue)) {
            return -1;
        }
        if ("audio".equals(attributeValue)) {
            return 1;
        }
        if ("video".equals(attributeValue)) {
            return 0;
        }
        return ("text".equals(attributeValue) || "image".equals(attributeValue)) ? 2 : -1;
    }
}
