package c.c.a.a.p0.j; import android.text.Layout; import android.util.Log; import android.util.Pair; import b.b.k.k; import c.c.a.a.b0; import c.c.a.a.p0.d; import c.c.a.a.r0.t; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; public final class c implements d { /* renamed from: b reason: collision with root package name */ public static final Pattern f1472b = Pattern.compile("^([0-9][0-9]+):([0-9][0-9]):([0-9][0-9])(?:(\\.[0-9]+)|:([0-9][0-9])(?:\\.([0-9]+))?)?$"); /* renamed from: c reason: collision with root package name */ public static final Pattern f1473c = Pattern.compile("^([0-9]+(?:\\.[0-9]+)?)(h|m|s|ms|f|t)$"); /* renamed from: d reason: collision with root package name */ public static final Pattern f1474d = Pattern.compile("^(([0-9]*.)?[0-9]+)(px|em|%)$"); public static final Pattern e = Pattern.compile("^(\\d+\\.?\\d*?)% (\\d+\\.?\\d*?)%$"); public static final a f = new a(30.0f, 1, 1); public final XmlPullParserFactory a; public static final class a { public final float a; /* renamed from: b reason: collision with root package name */ public final int f1475b; /* renamed from: c reason: collision with root package name */ public final int f1476c; public a(float f, int i, int i2) { this.a = f; this.f1475b = i; this.f1476c = i2; } } public c() { try { XmlPullParserFactory newInstance = XmlPullParserFactory.newInstance(); this.a = newInstance; newInstance.setNamespaceAware(true); } catch (XmlPullParserException e2) { throw new RuntimeException("Couldn't create XmlPullParserFactory instance", e2); } } public static long a(String str, a aVar) { double d2; double d3; double d4; Matcher matcher = f1472b.matcher(str); if (matcher.matches()) { double parseLong = (double) (Long.parseLong(matcher.group(1)) * 3600); double parseLong2 = (double) (Long.parseLong(matcher.group(2)) * 60); Double.isNaN(parseLong); Double.isNaN(parseLong2); double d5 = parseLong + parseLong2; double parseLong3 = (double) Long.parseLong(matcher.group(3)); Double.isNaN(parseLong3); double d6 = d5 + parseLong3; String group = matcher.group(4); double d7 = 0.0d; double parseDouble = d6 + (group != null ? Double.parseDouble(group) : 0.0d); String group2 = matcher.group(5); double parseLong4 = parseDouble + (group2 != null ? (double) (((float) Long.parseLong(group2)) / aVar.a) : 0.0d); String group3 = matcher.group(6); if (group3 != null) { double parseLong5 = (double) Long.parseLong(group3); double d8 = (double) aVar.f1475b; Double.isNaN(parseLong5); Double.isNaN(d8); double d9 = (double) aVar.a; Double.isNaN(d9); d7 = (parseLong5 / d8) / d9; } d2 = parseLong4 + d7; } else { Matcher matcher2 = f1473c.matcher(str); if (matcher2.matches()) { d2 = Double.parseDouble(matcher2.group(1)); String group4 = matcher2.group(2); if (group4.equals("h")) { d3 = 3600.0d; } else if (group4.equals("m")) { d3 = 60.0d; } else if (!group4.equals("s")) { if (group4.equals("ms")) { d4 = 1000.0d; } else { if (group4.equals("f")) { d4 = (double) aVar.a; } else if (group4.equals("t")) { d4 = (double) aVar.f1476c; } Double.isNaN(d4); } d2 /= d4; } d2 *= d3; } else { throw new b0(c.b.a.a.a.a("Malformed time expression: ", str)); } } return (long) (d2 * 1000000.0d); } public static void a(String str, e eVar) { Matcher matcher; String[] split = str.split("\\s+"); if (split.length == 1) { matcher = f1474d.matcher(str); } else if (split.length == 2) { matcher = f1474d.matcher(split[1]); Log.w("TtmlParser", "Multiple values in fontSize attribute. Picking the second value for vertical font size and ignoring the first."); } else { StringBuilder a2 = c.b.a.a.a.a("Invalid number of entries for fontSize: "); a2.append(split.length); a2.append("."); throw new b0(a2.toString()); } if (matcher.matches()) { String group = matcher.group(3); char c2 = 65535; int hashCode = group.hashCode(); if (hashCode != 37) { if (hashCode != 3240) { if (hashCode == 3592 && group.equals("px")) { c2 = 0; } } else if (group.equals("em")) { c2 = 1; } } else if (group.equals("%")) { c2 = 2; } if (c2 == 0) { eVar.j = 1; } else if (c2 == 1) { eVar.j = 2; } else if (c2 == 2) { eVar.j = 3; } else { throw new b0(c.b.a.a.a.a("Invalid unit for fontSize: '", group, "'.")); } eVar.k = Float.valueOf(matcher.group(1)).floatValue(); return; } throw new b0(c.b.a.a.a.a("Invalid expression for fontSize: '", str, "'.")); } public static boolean b(String str) { return str.equals("tt") || str.equals("head") || str.equals("body") || str.equals("div") || str.equals("p") || str.equals("span") || str.equals("br") || str.equals("style") || str.equals("styling") || str.equals("layout") || str.equals("region") || str.equals("metadata") || str.equals("smpte:image") || str.equals("smpte:data") || str.equals("smpte:information"); } @Override // c.c.a.a.p0.d public c.c.a.a.p0.c a(byte[] bArr, int i, int i2) { try { XmlPullParser newPullParser = this.a.newPullParser(); Map<String, e> hashMap = new HashMap<>(); HashMap hashMap2 = new HashMap(); hashMap2.put("", new d()); InputStream byteArrayInputStream = new ByteArrayInputStream(bArr, i, i2); f fVar = null; newPullParser.setInput(byteArrayInputStream, null); LinkedList linkedList = new LinkedList(); int i3 = 0; a aVar = f; for (int eventType = newPullParser.getEventType(); eventType != 1; eventType = newPullParser.getEventType()) { b bVar = (b) linkedList.peekLast(); if (i3 == 0) { String name = newPullParser.getName(); if (eventType == 2) { if ("tt".equals(name)) { aVar = a(newPullParser); } if (!b(name)) { Log.i("TtmlParser", "Ignoring unsupported tag: " + newPullParser.getName()); } else if ("head".equals(name)) { a(newPullParser, hashMap, hashMap2); } else { try { b a2 = a(newPullParser, bVar, hashMap2, aVar); linkedList.addLast(a2); if (bVar != null) { bVar.a(a2); } } catch (b0 e2) { Log.w("TtmlParser", "Suppressing parser error", e2); } } } else if (eventType == 4) { b a3 = b.a(newPullParser.getText()); if (bVar.k == null) { bVar.k = new ArrayList(); } bVar.k.add(a3); } else if (eventType == 3) { if (newPullParser.getName().equals("tt")) { fVar = new f((b) linkedList.getLast(), hashMap, hashMap2); } linkedList.removeLast(); } newPullParser.next(); } else if (eventType != 2) { if (eventType == 3) { i3--; } newPullParser.next(); } i3++; newPullParser.next(); } return fVar; } catch (XmlPullParserException e3) { throw new b0("Unable to parse source", e3); } catch (IOException e4) { throw new IllegalStateException("Unexpected error when reading input.", e4); } } public final b a(XmlPullParser xmlPullParser, b bVar, Map<String, d> map, a aVar) { long j; int attributeCount = xmlPullParser.getAttributeCount(); e a2 = a(xmlPullParser, (e) null); String[] strArr = null; long j2 = 0; long j3 = -1; long j4 = -1; String str = ""; for (int i = 0; i < attributeCount; i++) { String attributeName = xmlPullParser.getAttributeName(i); String attributeValue = xmlPullParser.getAttributeValue(i); if ("begin".equals(attributeName)) { j3 = a(attributeValue, aVar); } else if ("end".equals(attributeName)) { j4 = a(attributeValue, aVar); } else if ("dur".equals(attributeName)) { j2 = a(attributeValue, aVar); } else if ("style".equals(attributeName)) { String[] split = attributeValue.split("\\s+"); if (split.length > 0) { strArr = split; } } else if ("region".equals(attributeName)) { if (map.containsKey(attributeValue)) { str = attributeValue; } } } if (bVar != null) { long j5 = bVar.f1471d; if (j5 != -1) { if (j3 != -1) { j3 += j5; } if (j4 != -1) { j4 += bVar.f1471d; } } } if (j4 == -1) { if (j2 > 0) { j = j3 + j2; } else if (bVar != null) { long j6 = bVar.e; if (j6 != -1) { j = j6; } } return new b(xmlPullParser.getName(), null, j3, j, a2, strArr, str); } j = j4; return new b(xmlPullParser.getName(), null, j3, j, a2, strArr, str); } public final a a(XmlPullParser xmlPullParser) { String attributeValue = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "frameRate"); int parseInt = attributeValue != null ? Integer.parseInt(attributeValue) : 30; float f2 = 1.0f; String attributeValue2 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "frameRateMultiplier"); if (attributeValue2 != null) { String[] split = attributeValue2.split(" "); if (split.length == 2) { f2 = ((float) Integer.parseInt(split[0])) / ((float) Integer.parseInt(split[1])); } else { throw new b0("frameRateMultiplier doesn't have 2 parts"); } } int i = f.f1475b; String attributeValue3 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "subFrameRate"); if (attributeValue3 != null) { i = Integer.parseInt(attributeValue3); } int i2 = f.f1476c; String attributeValue4 = xmlPullParser.getAttributeValue("http://www.w3.org/ns/ttml#parameter", "tickRate"); if (attributeValue4 != null) { i2 = Integer.parseInt(attributeValue4); } return new a(((float) parseInt) * f2, i, i2); } public final e a(e eVar) { return eVar == null ? new e() : eVar; } /* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */ public final e a(XmlPullParser xmlPullParser, e eVar) { char c2; String str; StringBuilder sb; Layout.Alignment alignment; int attributeCount = xmlPullParser.getAttributeCount(); for (int i = 0; i < attributeCount; i++) { String attributeValue = xmlPullParser.getAttributeValue(i); String attributeName = xmlPullParser.getAttributeName(i); char c3 = 65535; int i2 = 2; switch (attributeName.hashCode()) { case -1550943582: if (attributeName.equals("fontStyle")) { c2 = 6; break; } c2 = 65535; break; case -1224696685: if (attributeName.equals("fontFamily")) { c2 = 3; break; } c2 = 65535; break; case -1065511464: if (attributeName.equals("textAlign")) { c2 = 7; break; } c2 = 65535; break; case -879295043: if (attributeName.equals("textDecoration")) { c2 = '\b'; break; } c2 = 65535; break; case -734428249: if (attributeName.equals("fontWeight")) { c2 = 5; break; } c2 = 65535; break; case 3355: if (attributeName.equals("id")) { c2 = 0; break; } c2 = 65535; break; case 94842723: if (attributeName.equals("color")) { c2 = 2; break; } c2 = 65535; break; case 365601008: if (attributeName.equals("fontSize")) { c2 = 4; break; } c2 = 65535; break; case 1287124693: if (attributeName.equals("backgroundColor")) { c2 = 1; break; } c2 = 65535; break; default: c2 = 65535; break; } switch (c2) { case 0: if ("style".equals(xmlPullParser.getName())) { eVar = a(eVar); eVar.l = attributeValue; continue; } case 1: eVar = a(eVar); try { eVar.f1482d = a.a(attributeValue); eVar.e = true; continue; } catch (IllegalArgumentException unused) { sb = new StringBuilder(); str = "failed parsing background value: '"; break; } case 2: eVar = a(eVar); try { int a2 = a.a(attributeValue); if (eVar != null) { k.i.b(true); eVar.f1480b = a2; eVar.f1481c = true; continue; } else { throw null; } } catch (IllegalArgumentException unused2) { sb = new StringBuilder(); str = "failed parsing color value: '"; break; } case 3: eVar = a(eVar); if (eVar != null) { k.i.b(true); eVar.a = attributeValue; continue; } else { throw null; } case 4: try { eVar = a(eVar); a(attributeValue, eVar); continue; } catch (b0 unused3) { sb = new StringBuilder(); str = "failed parsing fontSize value: '"; break; } case 5: eVar = a(eVar); boolean equalsIgnoreCase = "bold".equalsIgnoreCase(attributeValue); if (eVar != null) { k.i.b(true); eVar.h = equalsIgnoreCase ? 1 : 0; continue; } else { throw null; } case 6: eVar = a(eVar); boolean equalsIgnoreCase2 = "italic".equalsIgnoreCase(attributeValue); if (eVar != null) { k.i.b(true); if (!equalsIgnoreCase2) { i2 = 0; } eVar.i = i2; continue; } else { throw null; } case 7: String e2 = t.e(attributeValue); switch (e2.hashCode()) { case -1364013995: if (e2.equals("center")) { c3 = 4; break; } break; case 100571: if (e2.equals("end")) { c3 = 3; break; } break; case 3317767: if (e2.equals("left")) { c3 = 0; break; } break; case 108511772: if (e2.equals("right")) { c3 = 2; break; } break; case 109757538: if (e2.equals("start")) { c3 = 1; break; } break; } if (c3 == 0 || c3 == 1) { eVar = a(eVar); alignment = Layout.Alignment.ALIGN_NORMAL; } else if (c3 == 2 || c3 == 3) { eVar = a(eVar); alignment = Layout.Alignment.ALIGN_OPPOSITE; } else if (c3 == 4) { eVar = a(eVar); alignment = Layout.Alignment.ALIGN_CENTER; } eVar.m = alignment; continue; case '\b': String e3 = t.e(attributeValue); switch (e3.hashCode()) { case -1461280213: if (e3.equals("nounderline")) { c3 = 3; break; } break; case -1026963764: if (e3.equals("underline")) { c3 = 2; break; } break; case 913457136: if (e3.equals("nolinethrough")) { c3 = 1; break; } break; case 1679736913: if (e3.equals("linethrough")) { c3 = 0; break; } break; } if (c3 == 0) { eVar = a(eVar); if (eVar != null) { k.i.b(true); eVar.f = 1; } else { throw null; } } else if (c3 == 1) { eVar = a(eVar); if (eVar != null) { k.i.b(true); eVar.f = 0; } else { throw null; } } else if (c3 == 2) { eVar = a(eVar); if (eVar != null) { k.i.b(true); eVar.g = 1; } else { throw null; } } else if (c3 == 3) { eVar = a(eVar); if (eVar != null) { k.i.b(true); eVar.g = 0; continue; } else { throw null; } } else { continue; } default: } sb.append(str); sb.append(attributeValue); sb.append("'"); Log.w("TtmlParser", sb.toString()); } return eVar; } /* JADX DEBUG: Multi-variable search result rejected for r19v0, resolved type: java.util.Map<java.lang.String, c.c.a.a.p0.j.d> */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARNING: Removed duplicated region for block: B:26:0x00aa */ /* JADX WARNING: Removed duplicated region for block: B:36:0x00dd */ /* JADX WARNING: Removed duplicated region for block: B:42:0x00fc */ /* JADX WARNING: Removed duplicated region for block: B:43:0x00fe */ public final Map<String, e> a(XmlPullParser xmlPullParser, Map<String, e> map, Map<String, d> map2) { boolean z; float f2; float f3; float f4; String[] split; do { xmlPullParser.next(); z = false; if (k.i.c(xmlPullParser, "style")) { String a2 = k.i.a(xmlPullParser, "style"); e a3 = a(xmlPullParser, new e()); if (a2 != null) { for (String str : a2.split("\\s+")) { a3.a(map.get(str)); } } String str2 = a3.l; if (str2 != null) { map.put(str2, a3); } } else if (k.i.c(xmlPullParser, "region")) { String a4 = k.i.a(xmlPullParser, "id"); String a5 = k.i.a(xmlPullParser, "origin"); String a6 = k.i.a(xmlPullParser, "extent"); Pair pair = null; if (!(a5 == null || a4 == null)) { Matcher matcher = e.matcher(a5); if (matcher.matches()) { try { f2 = Float.parseFloat(matcher.group(1)) / 100.0f; f3 = Float.parseFloat(matcher.group(2)) / 100.0f; } catch (NumberFormatException e2) { Log.w("TtmlParser", "Ignoring region with malformed origin: '" + a5 + "'", e2); } if (a6 != null) { Matcher matcher2 = e.matcher(a6); if (matcher2.matches()) { try { f4 = Float.parseFloat(matcher2.group(1)) / 100.0f; } catch (NumberFormatException e3) { Log.w("TtmlParser", "Ignoring malformed region extent: '" + a6 + "'", e3); } if (f2 != Float.MIN_VALUE) { pair = new Pair(a4, new d(f2, f3, 0, f4)); } } } f4 = Float.MIN_VALUE; if (f2 != Float.MIN_VALUE) { } } f3 = Float.MIN_VALUE; f2 = Float.MIN_VALUE; if (a6 != null) { } f4 = Float.MIN_VALUE; if (f2 != Float.MIN_VALUE) { } } if (pair != null) { map2.put(pair.first, pair.second); if ((xmlPullParser.getEventType() != 3) && xmlPullParser.getName().equals("head")) { z = true; continue; } } } z = true; continue; } while (!z); return map; } @Override // c.c.a.a.p0.d public boolean a(String str) { return "application/ttml+xml".equals(str); } }