package t2;

import android.text.Layout;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.ColorParser;
import androidx.media3.common.util.Consumer;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.Util;
import androidx.media3.common.util.XmlPullParserUtil;
import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.extractor.text.SubtitleDecoderException;
import com.google.android.gms.measurement.internal.u1;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import n2.o;
import n2.p;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import xyz.stream.download.config.InnerConstant;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Pattern f32817b = Pattern.compile("^([0-9][0-9]+):([0-9][0-9]):([0-9][0-9])(?:(\\.[0-9]+)|:([0-9][0-9])(?:\\.([0-9]+))?)?$");

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final Pattern f32818c = Pattern.compile("^([0-9]+(?:\\.[0-9]+)?)(h|m|s|ms|f|t)$");

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Pattern f32819d = Pattern.compile("^(([0-9]*.)?[0-9]+)(px|em|%)$");

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Pattern f32820e = Pattern.compile("^([-+]?\\d+\\.?\\d*?)%$");

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Pattern f32821f = Pattern.compile("^([-+]?\\d+\\.?\\d*?)% ([-+]?\\d+\\.?\\d*?)%$");

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final Pattern f32822g = Pattern.compile("^([-+]?\\d+\\.?\\d*?)px ([-+]?\\d+\\.?\\d*?)px$");

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final Pattern f32823h = Pattern.compile("^(\\d+) (\\d+)$");

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final d f32824i = new d(30.0f, 1, 1);

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

    public f() {
        try {
            XmlPullParserFactory xmlPullParserFactoryNewInstance = XmlPullParserFactory.newInstance();
            this.f32825a = xmlPullParserFactoryNewInstance;
            xmlPullParserFactoryNewInstance.setNamespaceAware(true);
        } catch (XmlPullParserException e10) {
            throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e10);
        }
    }

    public static boolean c(String str) {
        return str.equals("tt") || str.equals("head") || str.equals("body") || str.equals("div") || str.equals("p") || str.equals("span") || str.equals(CmcdConfiguration.KEY_BITRATE) || str.equals("style") || str.equals("styling") || str.equals("layout") || str.equals("region") || str.equals("metadata") || str.equals(MimeTypes.BASE_TYPE_IMAGE) || str.equals("data") || str.equals("information");
    }

    private static i createIfNull(@Nullable i iVar) {
        return iVar == null ? new i() : iVar;
    }

    public static int e(XmlPullParser xmlPullParser) {
        String attributeValue = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "cellResolution");
        if (attributeValue == null) {
            return 15;
        }
        Matcher matcher = f32823h.matcher(attributeValue);
        if (!matcher.matches()) {
            Log.w("TtmlParser", "Ignoring malformed cell resolution: ".concat(attributeValue));
            return 15;
        }
        boolean z10 = true;
        try {
            int i10 = Integer.parseInt((String) Assertions.checkNotNull(matcher.group(1)));
            int i11 = Integer.parseInt((String) Assertions.checkNotNull(matcher.group(2)));
            if (i10 == 0 || i11 == 0) {
                z10 = false;
            }
            Assertions.checkArgument(z10, "Invalid cell resolution " + i10 + " " + i11);
            return i11;
        } catch (NumberFormatException unused) {
            Log.w("TtmlParser", "Ignoring malformed cell resolution: ".concat(attributeValue));
            return 15;
        }
    }

    public static void f(String str, i iVar) throws SubtitleDecoderException {
        Matcher matcher;
        String str2;
        String[] strArrSplit = Util.split(str, "\\s+");
        int length = strArrSplit.length;
        Pattern pattern = f32819d;
        if (length == 1) {
            matcher = pattern.matcher(str);
        } else {
            if (strArrSplit.length != 2) {
                throw new SubtitleDecoderException(u.a.b(new StringBuilder("Invalid number of entries for fontSize: "), strArrSplit.length, "."));
            }
            matcher = pattern.matcher(strArrSplit[1]);
            Log.w("TtmlParser", "Multiple values in fontSize attribute. Picking the second value for vertical font size and ignoring the first.");
        }
        if (!matcher.matches()) {
            throw new SubtitleDecoderException(u1.k("Invalid expression for fontSize: '", str, "'."));
        }
        str2 = (String) Assertions.checkNotNull(matcher.group(3));
        str2.getClass();
        str2.hashCode();
        switch (str2) {
            case "%":
                iVar.f32844i = 3;
                break;
            case "em":
                iVar.f32844i = 2;
                break;
            case "px":
                iVar.f32844i = 1;
                break;
            default:
                throw new SubtitleDecoderException(u1.k("Invalid unit for fontSize: '", str2, "'."));
        }
        iVar.f32846j = Float.parseFloat((String) Assertions.checkNotNull(matcher.group(1)));
    }

    public static d g(XmlPullParser xmlPullParser) {
        float f10;
        String attributeValue = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "frameRate");
        int i10 = attributeValue != null ? Integer.parseInt(attributeValue) : 30;
        String attributeValue2 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "frameRateMultiplier");
        if (attributeValue2 != null) {
            Assertions.checkArgument(Util.split(attributeValue2, " ").length == 2, "frameRateMultiplier doesn't have 2 parts");
            f10 = Integer.parseInt(r2[0]) / Integer.parseInt(r2[1]);
        } else {
            f10 = 1.0f;
        }
        d dVar = f32824i;
        int i11 = dVar.f32813b;
        String attributeValue3 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "subFrameRate");
        if (attributeValue3 != null) {
            i11 = Integer.parseInt(attributeValue3);
        }
        String attributeValue4 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "tickRate");
        return new d(i10 * f10, i11, attributeValue4 != null ? Integer.parseInt(attributeValue4) : dVar.f32814c);
    }

    public static i h(XmlPullParser xmlPullParser, i iVar) {
        String attributeValue;
        int attributeCount = xmlPullParser.getAttributeCount();
        for (int i10 = 0; i10 < attributeCount; i10++) {
            attributeValue = xmlPullParser.getAttributeValue(i10);
            String attributeName = xmlPullParser.getAttributeName(i10);
            attributeName.getClass();
            switch (attributeName) {
                case "fontStyle":
                    iVar = createIfNull(iVar);
                    iVar.f32843h = "italic".equalsIgnoreCase(attributeValue) ? 1 : 0;
                    break;
                case "extent":
                    iVar = createIfNull(iVar).setExtent(attributeValue);
                    break;
                case "fontFamily":
                    iVar = createIfNull(iVar).setFontFamily(attributeValue);
                    break;
                case "textAlign":
                    iVar = createIfNull(iVar).setTextAlign(parseAlignment(attributeValue));
                    break;
                case "origin":
                    iVar = createIfNull(iVar).setOrigin(attributeValue);
                    break;
                case "textDecoration":
                    String strQ = com.google.common.base.h.q(attributeValue);
                    strQ.getClass();
                    strQ.hashCode();
                    switch (strQ) {
                        case "nounderline":
                            iVar = createIfNull(iVar);
                            iVar.f32841f = 0;
                            break;
                        case "underline":
                            iVar = createIfNull(iVar);
                            iVar.f32841f = 1;
                            break;
                        case "nolinethrough":
                            iVar = createIfNull(iVar);
                            iVar.f32840e = 0;
                            break;
                        case "linethrough":
                            iVar = createIfNull(iVar);
                            iVar.f32840e = 1;
                            break;
                    }
                    break;
                case "fontWeight":
                    iVar = createIfNull(iVar);
                    iVar.f32842g = "bold".equalsIgnoreCase(attributeValue) ? 1 : 0;
                    break;
                case "id":
                    if (!"style".equals(xmlPullParser.getName())) {
                        break;
                    } else {
                        iVar = createIfNull(iVar).setId(attributeValue);
                        break;
                    }
                    break;
                case "ruby":
                    String strQ2 = com.google.common.base.h.q(attributeValue);
                    strQ2.getClass();
                    strQ2.hashCode();
                    switch (strQ2) {
                        case "baseContainer":
                        case "base":
                            iVar = createIfNull(iVar);
                            iVar.f32847k = 2;
                            break;
                        case "container":
                            iVar = createIfNull(iVar);
                            iVar.f32847k = 1;
                            break;
                        case "delimiter":
                            iVar = createIfNull(iVar);
                            iVar.f32847k = 4;
                            break;
                        case "textContainer":
                        case "text":
                            iVar = createIfNull(iVar);
                            iVar.f32847k = 3;
                            break;
                    }
                    break;
                case "color":
                    iVar = createIfNull(iVar);
                    try {
                        iVar.f32836a = ColorParser.parseTtmlColor(attributeValue);
                        iVar.f32837b = true;
                        break;
                    } catch (IllegalArgumentException unused) {
                        defpackage.e.A("Failed parsing color value: ", attributeValue, "TtmlParser");
                        break;
                    }
                    break;
                case "shear":
                    iVar = createIfNull(iVar);
                    Matcher matcher = f32820e.matcher(attributeValue);
                    float fMin = Float.MAX_VALUE;
                    if (matcher.matches()) {
                        try {
                            fMin = Math.min(100.0f, Math.max(-100.0f, Float.parseFloat((String) Assertions.checkNotNull(matcher.group(1)))));
                        } catch (NumberFormatException e10) {
                            Log.w("TtmlParser", "Failed to parse shear: " + attributeValue, e10);
                        }
                        break;
                    } else {
                        defpackage.e.A("Invalid value for shear: ", attributeValue, "TtmlParser");
                    }
                    iVar.f32850n = fMin;
                    break;
                case "textCombine":
                    String strQ3 = com.google.common.base.h.q(attributeValue);
                    strQ3.getClass();
                    if (!strQ3.equals("all")) {
                        if (strQ3.equals("none")) {
                            iVar = createIfNull(iVar);
                            iVar.f32849m = 0;
                        }
                        break;
                    } else {
                        iVar = createIfNull(iVar);
                        iVar.f32849m = 1;
                        break;
                    }
                    break;
                case "fontSize":
                    try {
                        iVar = createIfNull(iVar);
                        f(attributeValue, iVar);
                        break;
                    } catch (SubtitleDecoderException unused2) {
                        defpackage.e.A("Failed parsing fontSize value: ", attributeValue, "TtmlParser");
                        break;
                    }
                    break;
                case "textEmphasis":
                    iVar = createIfNull(iVar).setTextEmphasis(b.parse(attributeValue));
                    break;
                case "rubyPosition":
                    String strQ4 = com.google.common.base.h.q(attributeValue);
                    strQ4.getClass();
                    if (!strQ4.equals("before")) {
                        if (strQ4.equals("after")) {
                            iVar = createIfNull(iVar);
                            iVar.f32848l = 2;
                        }
                        break;
                    } else {
                        iVar = createIfNull(iVar);
                        iVar.f32848l = 1;
                        break;
                    }
                    break;
                case "backgroundColor":
                    iVar = createIfNull(iVar);
                    try {
                        iVar.f32838c = ColorParser.parseTtmlColor(attributeValue);
                        iVar.f32839d = true;
                        break;
                    } catch (IllegalArgumentException unused3) {
                        defpackage.e.A("Failed parsing background value: ", attributeValue, "TtmlParser");
                        break;
                    }
                    break;
                case "multiRowAlign":
                    iVar = createIfNull(iVar).setMultiRowAlign(parseAlignment(attributeValue));
                    break;
            }
        }
        return iVar;
    }

    public static long i(String str, d dVar) throws SubtitleDecoderException {
        double d10;
        double d11;
        double d12;
        Matcher matcher = f32817b.matcher(str);
        if (matcher.matches()) {
            double d13 = (Long.parseLong((String) Assertions.checkNotNull(matcher.group(1))) * 3600) + (Long.parseLong((String) Assertions.checkNotNull(matcher.group(2))) * 60) + Long.parseLong((String) Assertions.checkNotNull(matcher.group(3)));
            String strGroup = matcher.group(4);
            return (long) ((d13 + (strGroup != null ? Double.parseDouble(strGroup) : 0.0d) + (matcher.group(5) != null ? Long.parseLong(r13) / dVar.f32812a : 0.0d) + (matcher.group(6) != null ? (Long.parseLong(r13) / ((double) dVar.f32813b)) / ((double) dVar.f32812a) : 0.0d)) * 1000000.0d);
        }
        Matcher matcher2 = f32818c.matcher(str);
        if (!matcher2.matches()) {
            throw new SubtitleDecoderException(defpackage.e.i("Malformed time expression: ", str));
        }
        d10 = Double.parseDouble((String) Assertions.checkNotNull(matcher2.group(1)));
        String str2 = (String) Assertions.checkNotNull(matcher2.group(2));
        str2.getClass();
        str2.hashCode();
        switch (str2) {
            case "f":
                d11 = dVar.f32812a;
                d10 /= d11;
                return (long) (d10 * 1000000.0d);
            case "h":
                d12 = 3600.0d;
                break;
            case "m":
                d12 = 60.0d;
                break;
            case "t":
                d11 = dVar.f32814c;
                d10 /= d11;
                return (long) (d10 * 1000000.0d);
            case "ms":
                d11 = 1000.0d;
                d10 /= d11;
                return (long) (d10 * 1000000.0d);
            default:
                return (long) (d10 * 1000000.0d);
        }
        d10 *= d12;
        return (long) (d10 * 1000000.0d);
    }

    @Nullable
    private static Layout.Alignment parseAlignment(String str) {
        String strQ = com.google.common.base.h.q(str);
        strQ.getClass();
        switch (strQ) {
            case "center":
                return Layout.Alignment.ALIGN_CENTER;
            case "end":
            case "right":
                return Layout.Alignment.ALIGN_OPPOSITE;
            case "left":
            case "start":
                return Layout.Alignment.ALIGN_NORMAL;
            default:
                return null;
        }
    }

    private static Map<String, i> parseHeader(XmlPullParser xmlPullParser, Map<String, i> map, int i10, @Nullable e eVar, Map<String, g> map2, Map<String, String> map3) throws XmlPullParserException, IOException {
        String attributeValue;
        do {
            xmlPullParser.next();
            if (XmlPullParserUtil.isStartTag(xmlPullParser, "style")) {
                String attributeValue2 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "style");
                i iVarH = h(xmlPullParser, new i());
                if (attributeValue2 != null) {
                    String strTrim = attributeValue2.trim();
                    for (String str : strTrim.isEmpty() ? new String[0] : Util.split(strTrim, "\\s+")) {
                        iVarH.chain(map.get(str));
                    }
                }
                String id2 = iVarH.getId();
                if (id2 != null) {
                    map.put(id2, iVarH);
                }
            } else if (XmlPullParserUtil.isStartTag(xmlPullParser, "region")) {
                g regionAttributes = parseRegionAttributes(xmlPullParser, i10, eVar, map);
                if (regionAttributes != null) {
                    map2.put(regionAttributes.f32826a, regionAttributes);
                }
            } else if (XmlPullParserUtil.isStartTag(xmlPullParser, "metadata")) {
                do {
                    xmlPullParser.next();
                    if (XmlPullParserUtil.isStartTag(xmlPullParser, MimeTypes.BASE_TYPE_IMAGE) && (attributeValue = XmlPullParserUtil.getAttributeValue(xmlPullParser, InnerConstant.Db.f36069id)) != null) {
                        map3.put(attributeValue, xmlPullParser.nextText());
                    }
                } while (!XmlPullParserUtil.isEndTag(xmlPullParser, "metadata"));
            }
        } while (!XmlPullParserUtil.isEndTag(xmlPullParser, "head"));
        return map;
    }

    /* JADX WARN: Removed duplicated region for block: B:72:0x0108  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static c parseNode(XmlPullParser xmlPullParser, @Nullable c cVar, Map<String, g> map, d dVar) throws SubtitleDecoderException {
        long j10;
        long j11;
        String attributeValue;
        int attributeCount = xmlPullParser.getAttributeCount();
        i iVarH = h(xmlPullParser, null);
        String[] strArr = null;
        String strSubstring = null;
        String str = "";
        long jI = -9223372036854775807L;
        long jI2 = -9223372036854775807L;
        long jI3 = -9223372036854775807L;
        for (int i10 = 0; i10 < attributeCount; i10++) {
            String attributeName = xmlPullParser.getAttributeName(i10);
            attributeValue = xmlPullParser.getAttributeValue(i10);
            attributeName.getClass();
            switch (attributeName) {
                case "region":
                    if (map.containsKey(attributeValue)) {
                        str = attributeValue;
                        break;
                    } else {
                        break;
                    }
                    break;
                case "dur":
                    jI3 = i(attributeValue, dVar);
                    break;
                case "end":
                    jI2 = i(attributeValue, dVar);
                    break;
                case "begin":
                    jI = i(attributeValue, dVar);
                    break;
                case "style":
                    String strTrim = attributeValue.trim();
                    String[] strArrSplit = strTrim.isEmpty() ? new String[0] : Util.split(strTrim, "\\s+");
                    if (strArrSplit.length > 0) {
                        strArr = strArrSplit;
                    }
                    break;
                case "backgroundImage":
                    if (attributeValue.startsWith("#")) {
                        strSubstring = attributeValue.substring(1);
                        break;
                    }
            }
        }
        if (cVar != null) {
            long j12 = cVar.f32806b;
            j10 = -9223372036854775807L;
            if (j12 != -9223372036854775807L) {
                if (jI != -9223372036854775807L) {
                    jI += j12;
                }
                if (jI2 != -9223372036854775807L) {
                    jI2 += j12;
                }
            }
        } else {
            j10 = -9223372036854775807L;
        }
        long j13 = jI;
        if (jI2 != j10) {
            j11 = jI2;
        } else if (jI3 != j10) {
            j11 = j13 + jI3;
        } else if (cVar != null) {
            long j14 = cVar.f32807c;
            if (j14 != j10) {
                j11 = j14;
            }
        }
        return c.buildNode(xmlPullParser.getName(), j13, j11, iVarH, strArr, str, strSubstring, cVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:69:0x018f  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x01d8  */
    @Nullable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static g parseRegionAttributes(XmlPullParser xmlPullParser, int i10, @Nullable e eVar, Map<String, i> map) {
        float f10;
        float f11;
        int i11;
        float f12;
        float f13;
        int i12;
        int i13;
        int i14;
        float f14;
        float f15;
        String attributeValue;
        i iVar;
        String attributeValue2;
        i iVar2;
        String attributeValue3 = XmlPullParserUtil.getAttributeValue(xmlPullParser, InnerConstant.Db.f36069id);
        if (attributeValue3 == null) {
            return null;
        }
        String attributeValue4 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "origin");
        if (attributeValue4 == null && (attributeValue2 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "style")) != null && (iVar2 = map.get(attributeValue2)) != null) {
            attributeValue4 = iVar2.getOrigin();
        }
        Pattern pattern = f32822g;
        Pattern pattern2 = f32821f;
        if (attributeValue4 != null) {
            Matcher matcher = pattern2.matcher(attributeValue4);
            Matcher matcher2 = pattern.matcher(attributeValue4);
            if (matcher.matches()) {
                try {
                    f11 = Float.parseFloat((String) Assertions.checkNotNull(matcher.group(1))) / 100.0f;
                    f10 = Float.parseFloat((String) Assertions.checkNotNull(matcher.group(2))) / 100.0f;
                } catch (NumberFormatException unused) {
                    Log.w("TtmlParser", "Ignoring region with malformed origin: ".concat(attributeValue4));
                    return null;
                }
            } else {
                if (!matcher2.matches()) {
                    Log.w("TtmlParser", "Ignoring region with unsupported origin: ".concat(attributeValue4));
                    return null;
                }
                if (eVar == null) {
                    Log.w("TtmlParser", "Ignoring region with missing tts:extent: ".concat(attributeValue4));
                    return null;
                }
                try {
                    int i15 = Integer.parseInt((String) Assertions.checkNotNull(matcher2.group(1)));
                    float f16 = i15 / eVar.f32815a;
                    f10 = Integer.parseInt((String) Assertions.checkNotNull(matcher2.group(2))) / eVar.f32816b;
                    f11 = f16;
                } catch (NumberFormatException unused2) {
                    Log.w("TtmlParser", "Ignoring region with malformed origin: ".concat(attributeValue4));
                    return null;
                }
            }
        } else {
            f10 = 0.0f;
            f11 = 0.0f;
        }
        String attributeValue5 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "extent");
        if (attributeValue5 == null && (attributeValue = XmlPullParserUtil.getAttributeValue(xmlPullParser, "style")) != null && (iVar = map.get(attributeValue)) != null) {
            attributeValue5 = iVar.getExtent();
        }
        if (attributeValue5 != null) {
            Matcher matcher3 = pattern2.matcher(attributeValue5);
            Matcher matcher4 = pattern.matcher(attributeValue5);
            if (matcher3.matches()) {
                try {
                    f14 = Float.parseFloat((String) Assertions.checkNotNull(matcher3.group(1))) / 100.0f;
                    f15 = Float.parseFloat((String) Assertions.checkNotNull(matcher3.group(2))) / 100.0f;
                    i11 = 2;
                } catch (NumberFormatException unused3) {
                    defpackage.e.A("Ignoring region with malformed extent: ", attributeValue4, "TtmlParser");
                    return null;
                }
            } else {
                if (!matcher4.matches()) {
                    defpackage.e.A("Ignoring region with unsupported extent: ", attributeValue4, "TtmlParser");
                    return null;
                }
                if (eVar == null) {
                    defpackage.e.A("Ignoring region with missing tts:extent: ", attributeValue4, "TtmlParser");
                    return null;
                }
                try {
                    int i16 = Integer.parseInt((String) Assertions.checkNotNull(matcher4.group(1)));
                    i11 = 2;
                    float f17 = i16 / eVar.f32815a;
                    f15 = Integer.parseInt((String) Assertions.checkNotNull(matcher4.group(2))) / eVar.f32816b;
                    f14 = f17;
                } catch (NumberFormatException unused4) {
                    defpackage.e.A("Ignoring region with malformed extent: ", attributeValue4, "TtmlParser");
                    return null;
                }
            }
            f12 = f14;
            f13 = f15;
        } else {
            i11 = 2;
            f12 = 1.0f;
            f13 = 1.0f;
        }
        String attributeValue6 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "displayAlign");
        if (attributeValue6 != null) {
            String strQ = com.google.common.base.h.q(attributeValue6);
            strQ.getClass();
            if (strQ.equals("center")) {
                f10 = (f13 / 2.0f) + f10;
                i13 = 1;
                i12 = i10;
            } else if (strQ.equals("after")) {
                f10 += f13;
                i12 = i10;
                i13 = i11;
            } else {
                i12 = i10;
                i13 = 0;
            }
        }
        float f18 = 1.0f / i12;
        String attributeValue7 = XmlPullParserUtil.getAttributeValue(xmlPullParser, "writingMode");
        if (attributeValue7 != null) {
            String strQ2 = com.google.common.base.h.q(attributeValue7);
            strQ2.getClass();
            strQ2.hashCode();
            switch (strQ2) {
                case "tb":
                case "tblr":
                    i14 = i11;
                    break;
                case "tbrl":
                    i14 = 1;
                    break;
                default:
                    i14 = Integer.MIN_VALUE;
                    break;
            }
        }
        return new g(attributeValue3, f11, f10, 0, i13, f12, f13, 1, f18, i14);
    }

    @Nullable
    private static e parseTtsExtent(XmlPullParser xmlPullParser) {
        String attributeValue = XmlPullParserUtil.getAttributeValue(xmlPullParser, "extent");
        if (attributeValue == null) {
            return null;
        }
        Matcher matcher = f32822g.matcher(attributeValue);
        if (!matcher.matches()) {
            Log.w("TtmlParser", "Ignoring non-pixel tts extent: ".concat(attributeValue));
            return null;
        }
        try {
            return new e(Integer.parseInt((String) Assertions.checkNotNull(matcher.group(1))), Integer.parseInt((String) Assertions.checkNotNull(matcher.group(2))));
        } catch (NumberFormatException unused) {
            Log.w("TtmlParser", "Ignoring malformed tts extent: ".concat(attributeValue));
            return null;
        }
    }

    @Override // n2.p
    public final n2.g a(int i10, int i11, byte[] bArr) {
        d dVar;
        try {
            XmlPullParser xmlPullParserNewPullParser = this.f32825a.newPullParser();
            HashMap map = new HashMap();
            HashMap map2 = new HashMap();
            HashMap map3 = new HashMap();
            map2.put("", new g("", -3.4028235E38f, -3.4028235E38f, Integer.MIN_VALUE, Integer.MIN_VALUE, -3.4028235E38f, -3.4028235E38f, Integer.MIN_VALUE, -3.4028235E38f, Integer.MIN_VALUE));
            e ttsExtent = null;
            xmlPullParserNewPullParser.setInput(new ByteArrayInputStream(bArr, i10, i11), null);
            ArrayDeque arrayDeque = new ArrayDeque();
            d dVarG = f32824i;
            int iE = 15;
            j jVar = null;
            int i12 = 0;
            for (int eventType = xmlPullParserNewPullParser.getEventType(); eventType != 1; eventType = xmlPullParserNewPullParser.getEventType()) {
                c cVar = (c) arrayDeque.peek();
                if (i12 == 0) {
                    String name = xmlPullParserNewPullParser.getName();
                    if (eventType == 2) {
                        if ("tt".equals(name)) {
                            dVarG = g(xmlPullParserNewPullParser);
                            iE = e(xmlPullParserNewPullParser);
                            ttsExtent = parseTtsExtent(xmlPullParserNewPullParser);
                        }
                        e eVar = ttsExtent;
                        d dVar2 = dVarG;
                        int i13 = iE;
                        if (c(name)) {
                            if ("head".equals(name)) {
                                dVar = dVar2;
                                parseHeader(xmlPullParserNewPullParser, map, i13, eVar, map2, map3);
                            } else {
                                dVar = dVar2;
                                try {
                                    c node = parseNode(xmlPullParserNewPullParser, cVar, map2, dVar);
                                    arrayDeque.push(node);
                                    if (cVar != null) {
                                        if (cVar.f32811g == null) {
                                            cVar.f32811g = new ArrayList();
                                        }
                                        cVar.f32811g.add(node);
                                    }
                                } catch (SubtitleDecoderException e10) {
                                    Log.w("TtmlParser", "Suppressing parser error", e10);
                                    i12++;
                                }
                            }
                            dVarG = dVar;
                        } else {
                            Log.i("TtmlParser", "Ignoring unsupported tag: " + xmlPullParserNewPullParser.getName());
                            i12++;
                            dVarG = dVar2;
                        }
                        ttsExtent = eVar;
                        iE = i13;
                    } else if (eventType == 4) {
                        c cVar2 = (c) Assertions.checkNotNull(cVar);
                        c cVarA = c.a(xmlPullParserNewPullParser.getText());
                        if (cVar2.f32811g == null) {
                            cVar2.f32811g = new ArrayList();
                        }
                        cVar2.f32811g.add(cVarA);
                    } else if (eventType == 3) {
                        if (xmlPullParserNewPullParser.getName().equals("tt")) {
                            jVar = new j((c) Assertions.checkNotNull((c) arrayDeque.peek()), map, map2, map3);
                        }
                        arrayDeque.pop();
                    }
                } else if (eventType == 2) {
                    i12++;
                } else if (eventType == 3) {
                    i12--;
                }
                xmlPullParserNewPullParser.next();
            }
            return (n2.g) Assertions.checkNotNull(jVar);
        } catch (IOException e11) {
            throw new IllegalStateException("Unexpected error when reading input.", e11);
        } catch (XmlPullParserException e12) {
            throw new IllegalStateException("Unable to decode source", e12);
        }
    }

    @Override // n2.p
    public final void b(byte[] bArr, int i10, int i11, o oVar, Consumer consumer) {
        ua.b.K(a(i10, i11, bArr), oVar, consumer);
    }

    @Override // n2.p
    public final int d() {
        return 1;
    }
}
