package c.i.a.c.e2.m; import android.text.Layout; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.style.ForegroundColorSpan; import android.text.style.StyleSpan; import android.text.style.UnderlineSpan; import android.util.Log; import androidx.annotation.Nullable; import c.i.a.c.e2.f; import c.i.a.c.e2.i; import c.i.a.c.e2.j; import c.i.a.c.i2.f0; import c.i.a.c.i2.w; import com.google.android.exoplayer2.text.SubtitleDecoderException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; /* compiled from: Cea608Decoder */ public final class c extends e { public static final int[] g = {11, 1, 3, 12, 14, 5, 7, 9}; public static final int[] h = {0, 4, 8, 12, 16, 20, 24, 28}; public static final int[] i = {-1, -16711936, -16776961, -16711681, -65536, -256, -65281}; public static final int[] j = {32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 225, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 233, 93, 237, 243, 250, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 231, 247, 209, 241, 9632}; public static final int[] k = {174, 176, 189, 191, 8482, 162, 163, 9834, 224, 32, 232, 226, 234, 238, 244, 251}; public static final int[] l = {193, 201, 211, 218, 220, 252, 8216, 161, 42, 39, 8212, 169, 8480, 8226, 8220, 8221, 192, 194, 199, 200, 202, 203, 235, 206, 207, 239, 212, 217, 249, 219, 171, 187}; public static final int[] m = {195, 227, 205, 204, 236, 210, 242, 213, 245, 123, 125, 92, 94, 95, 124, 126, 196, 228, 214, 246, 223, 165, 164, 9474, 197, 229, 216, 248, 9484, 9488, 9492, 9496}; public static final boolean[] n = {false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false, false, true, true, false, true, false, false, true, false, true, true, false, true, false, false, true, true, false, false, true, false, true, true, false}; public boolean A; public byte B; public byte C; public int D = 0; public boolean E; public long F; public final w o = new w(); public final int p; public final int q; public final int r; /* renamed from: s reason: collision with root package name */ public final long f819s; public final ArrayList t = new ArrayList<>(); public a u = new a(0, 4); @Nullable public List v; @Nullable public List w; /* renamed from: x reason: collision with root package name */ public int f820x; /* renamed from: y reason: collision with root package name */ public int f821y; /* renamed from: z reason: collision with root package name */ public boolean f822z; /* compiled from: Cea608Decoder */ public static final class a { public final List a = new ArrayList(); public final List b = new ArrayList(); /* renamed from: c reason: collision with root package name */ public final StringBuilder f823c = new StringBuilder(); public int d; public int e; public int f; public int g; public int h; /* compiled from: Cea608Decoder */ /* renamed from: c.i.a.c.e2.m.c$a$a reason: collision with other inner class name */ public static class C0088a { public final int a; public final boolean b; /* renamed from: c reason: collision with root package name */ public int f824c; public C0088a(int i, boolean z2, int i2) { this.a = i; this.b = z2; this.f824c = i2; } } public a(int i, int i2) { f(i); this.h = i2; } public void a(char c2) { if (this.f823c.length() < 32) { this.f823c.append(c2); } } public void b() { int length = this.f823c.length(); if (length > 0) { this.f823c.delete(length - 1, length); for (int size = this.a.size() - 1; size >= 0; size--) { C0088a aVar = this.a.get(size); int i = aVar.f824c; if (i == length) { aVar.f824c = i - 1; } else { return; } } } } @Nullable public c.i.a.c.e2.c c(int i) { float f; int i2 = this.e + this.f; int i3 = 32 - i2; SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); for (int i4 = 0; i4 < this.b.size(); i4++) { SpannableString spannableString = this.b.get(i4); int i5 = f0.a; if (spannableString.length() > i3) { spannableString = spannableString.subSequence(0, i3); } spannableStringBuilder.append(spannableString); spannableStringBuilder.append('\n'); } SpannableString d = d(); int i6 = f0.a; int length = d.length(); CharSequence charSequence = d; if (length > i3) { charSequence = d.subSequence(0, i3); } spannableStringBuilder.append(charSequence); if (spannableStringBuilder.length() == 0) { return null; } int length2 = i3 - spannableStringBuilder.length(); int i7 = i2 - length2; int i8 = i != Integer.MIN_VALUE ? i : (this.g != 2 || (Math.abs(i7) >= 3 && length2 >= 0)) ? (this.g != 2 || i7 <= 0) ? 0 : 2 : 1; if (i8 != 1) { if (i8 == 2) { i2 = 32 - length2; } f = ((((float) i2) / 32.0f) * 0.8f) + 0.1f; } else { f = 0.5f; } int i9 = this.d; if (i9 > 7) { i9 = (i9 - 15) - 2; } else if (this.g == 1) { i9 -= this.h - 1; } return new c.i.a.c.e2.c(spannableStringBuilder, Layout.Alignment.ALIGN_NORMAL, null, (float) i9, 1, Integer.MIN_VALUE, f, i8, Integer.MIN_VALUE, -3.4028235E38f, -3.4028235E38f, -3.4028235E38f, false, -16777216, Integer.MIN_VALUE, 0.0f, null); } public final SpannableString d() { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(this.f823c); int length = spannableStringBuilder.length(); int i = 0; int i2 = -1; int i3 = -1; int i4 = 0; int i5 = -1; boolean z2 = false; int i6 = -1; while (i < this.a.size()) { C0088a aVar = this.a.get(i); boolean z3 = aVar.b; int i7 = aVar.a; if (i7 != 8) { boolean z4 = i7 == 7; if (i7 != 7) { i6 = c.i[i7]; } z2 = z4; } int i8 = aVar.f824c; i++; if (i8 != (i < this.a.size() ? this.a.get(i).f824c : length)) { if (i2 != -1 && !z3) { spannableStringBuilder.setSpan(new UnderlineSpan(), i2, i8, 33); i2 = -1; } else if (i2 == -1 && z3) { i2 = i8; } if (i3 != -1 && !z2) { spannableStringBuilder.setSpan(new StyleSpan(2), i3, i8, 33); i3 = -1; } else if (i3 == -1 && z2) { i3 = i8; } if (i6 != i5) { if (i5 != -1) { spannableStringBuilder.setSpan(new ForegroundColorSpan(i5), i4, i8, 33); } i4 = i8; i5 = i6; } } } if (!(i2 == -1 || i2 == length)) { spannableStringBuilder.setSpan(new UnderlineSpan(), i2, length, 33); } if (!(i3 == -1 || i3 == length)) { spannableStringBuilder.setSpan(new StyleSpan(2), i3, length, 33); } if (!(i4 == length || i5 == -1)) { spannableStringBuilder.setSpan(new ForegroundColorSpan(i5), i4, length, 33); } return new SpannableString(spannableStringBuilder); } public boolean e() { return this.a.isEmpty() && this.b.isEmpty() && this.f823c.length() == 0; } public void f(int i) { this.g = i; this.a.clear(); this.b.clear(); this.f823c.setLength(0); this.d = 15; this.e = 0; this.f = 0; } } public c(String str, int i2, long j2) { this.f819s = j2 > 0 ? j2 * 1000 : -9223372036854775807L; this.p = "application/x-mp4-cea-608".equals(str) ? 2 : 3; if (i2 == 1) { this.r = 0; this.q = 0; } else if (i2 == 2) { this.r = 1; this.q = 0; } else if (i2 == 3) { this.r = 0; this.q = 1; } else if (i2 != 4) { Log.w("Cea608Decoder", "Invalid channel. Defaulting to CC1."); this.r = 0; this.q = 0; } else { this.r = 1; this.q = 1; } l(0); k(); this.E = true; this.F = -9223372036854775807L; } @Override // c.i.a.c.e2.m.e public f e() { List list = this.v; this.w = list; Objects.requireNonNull(list); return new f(list); } /* JADX WARNING: Removed duplicated region for block: B:203:0x008f A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:213:0x0015 A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:24:0x0069 */ @Override // c.i.a.c.e2.m.e public void f(i iVar) { boolean z2; boolean z3; ByteBuffer byteBuffer = iVar.k; Objects.requireNonNull(byteBuffer); this.o.B(byteBuffer.array(), byteBuffer.limit()); boolean z4 = false; while (true) { int a2 = this.o.a(); int i2 = this.p; if (a2 >= i2) { byte s2 = i2 == 2 ? -4 : (byte) this.o.s(); int s3 = this.o.s(); int s4 = this.o.s(); if ((s2 & 2) == 0 && (s2 & 1) == this.q) { byte b = (byte) (s3 & 127); byte b2 = (byte) (s4 & 127); if (b != 0 || b2 != 0) { boolean z5 = this.f822z; if ((s2 & 4) == 4) { boolean[] zArr = n; if (zArr[s3] && zArr[s4]) { z2 = true; this.f822z = z2; if (z2) { if ((b & 240) == 16) { if (this.A && this.B == b && this.C == b2) { this.A = false; z3 = true; if (!z3) { } } else { this.A = true; this.B = b; this.C = b2; z3 = false; if (!z3) { if (z2) { if (1 <= b && b <= 15) { this.E = false; } else { if ((b & 247) == 20) { if (!(b2 == 32 || b2 == 47)) { switch (b2) { default: switch (b2) { case 42: case 43: this.E = false; break; } case 37: case 38: case 39: this.E = true; break; } } this.E = true; } } if (this.E) { int i3 = b & 224; if (i3 == 0) { this.D = (b >> 3) & 1; } if (this.D == this.r) { if (i3 == 0) { int i4 = b & 247; if (i4 == 17 && (b2 & 240) == 48) { this.u.a((char) k[b2 & 15]); } else { int i5 = b & 246; if (i5 == 18 && (b2 & 224) == 32) { this.u.b(); this.u.a((char) ((b & 1) == 0 ? l[b2 & 31] : m[b2 & 31])); } else { if (i4 == 17 && (b2 & 240) == 32) { this.u.a(' '); boolean z6 = (b2 & 1) == 1; a aVar = this.u; aVar.a.add(new a.C0088a((b2 >> 1) & 7, z6, aVar.f823c.length())); } else { if ((b & 240) == 16 && (b2 & 192) == 64) { int i6 = g[b & 7]; if ((b2 & 32) != 0) { i6++; } a aVar2 = this.u; if (i6 != aVar2.d) { if (this.f820x != 1 && !aVar2.e()) { a aVar3 = new a(this.f820x, this.f821y); this.u = aVar3; this.t.add(aVar3); } this.u.d = i6; } boolean z7 = (b2 & 16) == 16; boolean z8 = (b2 & 1) == 1; int i7 = (b2 >> 1) & 7; a aVar4 = this.u; aVar4.a.add(new a.C0088a(z7 ? 8 : i7, z8, aVar4.f823c.length())); if (z7) { this.u.e = h[i7]; } } else { if (i4 == 23 && b2 >= 33 && b2 <= 35) { this.u.f = b2 - 32; } else { if (i5 == 20 && (b2 & 240) == 32) { if (b2 == 32) { l(2); } else if (b2 != 41) { switch (b2) { case 37: l(1); m(2); break; case 38: l(1); m(3); break; case 39: l(1); m(4); break; default: int i8 = this.f820x; if (i8 != 0) { if (b2 == 33) { this.u.b(); break; } else { switch (b2) { case 44: this.v = Collections.emptyList(); int i9 = this.f820x; if (i9 == 1 || i9 == 3) { k(); break; } case 45: if (i8 == 1 && !this.u.e()) { a aVar5 = this.u; aVar5.b.add(aVar5.d()); aVar5.f823c.setLength(0); aVar5.a.clear(); int min = Math.min(aVar5.h, aVar5.d); while (aVar5.b.size() >= min) { aVar5.b.remove(0); } break; } case 46: k(); break; case 47: this.v = j(); k(); break; } } } break; } } else { l(3); } } } } } } } } else { a aVar6 = this.u; int[] iArr = j; aVar6.a((char) iArr[(b & Byte.MAX_VALUE) - 32]); if ((b2 & 224) != 0) { this.u.a((char) iArr[(b2 & Byte.MAX_VALUE) - 32]); } } } } } else if (z5) { k(); } z4 = true; } } } } this.A = false; z3 = false; if (!z3) { } } } z2 = false; this.f822z = z2; if (z2) { } this.A = false; z3 = false; if (!z3) { } } } } else if (z4) { int i10 = this.f820x; if (i10 == 1 || i10 == 3) { this.v = j(); this.F = this.e; return; } return; } else { return; } } } @Override // c.i.a.c.e2.m.e, c.i.a.c.x1.c public void flush() { super.flush(); this.v = null; this.w = null; l(0); m(4); k(); this.f822z = false; this.A = false; this.B = 0; this.C = 0; this.D = 0; this.E = true; this.F = -9223372036854775807L; } @Override // c.i.a.c.e2.m.e @Nullable /* renamed from: g */ public j b() throws SubtitleDecoderException { j pollFirst; j g2 = super.b(); if (g2 != null) { return g2; } long j2 = this.f819s; boolean z2 = false; if (j2 != -9223372036854775807L) { long j3 = this.F; if (j3 != -9223372036854775807L && this.e - j3 >= j2) { z2 = true; } } if (!z2 || (pollFirst = this.b.pollFirst()) == null) { return null; } List emptyList = Collections.emptyList(); this.v = emptyList; this.F = -9223372036854775807L; this.w = emptyList; Objects.requireNonNull(emptyList); pollFirst.r(this.e, new f(emptyList), Long.MAX_VALUE); return pollFirst; } @Override // c.i.a.c.e2.m.e public boolean h() { return this.v != this.w; } public final List j() { int size = this.t.size(); ArrayList arrayList = new ArrayList(size); int i2 = 2; for (int i3 = 0; i3 < size; i3++) { c.i.a.c.e2.c c2 = this.t.get(i3).c(Integer.MIN_VALUE); arrayList.add(c2); if (c2 != null) { i2 = Math.min(i2, c2.i); } } ArrayList arrayList2 = new ArrayList(size); for (int i4 = 0; i4 < size; i4++) { c.i.a.c.e2.c cVar = (c.i.a.c.e2.c) arrayList.get(i4); if (cVar != null) { if (cVar.i != i2) { cVar = this.t.get(i4).c(i2); Objects.requireNonNull(cVar); } arrayList2.add(cVar); } } return arrayList2; } public final void k() { this.u.f(this.f820x); this.t.clear(); this.t.add(this.u); } public final void l(int i2) { int i3 = this.f820x; if (i3 != i2) { this.f820x = i2; if (i2 == 3) { for (int i4 = 0; i4 < this.t.size(); i4++) { this.t.get(i4).g = i2; } return; } k(); if (i3 == 3 || i2 == 1 || i2 == 0) { this.v = Collections.emptyList(); } } } public final void m(int i2) { this.f821y = i2; this.u.h = i2; } @Override // c.i.a.c.e2.m.e, c.i.a.c.x1.c public void release() { } }