package com.applovin.impl; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.mbridge.msdk.playercommon.exoplayer2.C; import java.util.Collections; import kotlin.jvm.internal.ByteCompanionObject; /* loaded from: classes.dex */ public final class ia implements q7 { private final nj a; private String b; private qo c; private a d; private boolean e; private long l; private final boolean[] f = new boolean[3]; private final yf g = new yf(32, 128); private final yf h = new yf(33, 128); private final yf i = new yf(34, 128); private final yf j = new yf(39, 128); private final yf k = new yf(40, 128); private long m = C.TIME_UNSET; private final bh n = new bh(); @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.m = j; } } @Override // com.applovin.impl.q7 public void b() { } public ia(nj njVar) { this.a = njVar; } @Override // com.applovin.impl.q7 public void a(bh bhVar) { c(); while (bhVar.a() > 0) { int d = bhVar.d(); int e = bhVar.e(); byte[] c = bhVar.c(); this.l += bhVar.a(); this.c.a(bhVar, bhVar.a()); while (d < e) { int a2 = zf.a(c, d, e, this.f); if (a2 == e) { a(c, d, e); return; } int a3 = zf.a(c, a2); int i = a2 - d; if (i > 0) { a(c, d, a2); } int i2 = e - a2; long j = this.l - i2; a(j, i2, i < 0 ? -i : 0, this.m); b(j, i2, a3, this.m); d = a2 + 3; } } } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.b = dVar.b(); qo a2 = m8Var.a(dVar.c(), 2); this.c = a2; this.d = new a(a2); this.a.a(m8Var, dVar); } private static void b(ch chVar) { int f = chVar.f(); boolean z = false; int i = 0; for (int i2 = 0; i2 < f; i2++) { if (i2 != 0) { z = chVar.c(); } if (z) { chVar.g(); chVar.f(); for (int i3 = 0; i3 <= i; i3++) { if (chVar.c()) { chVar.g(); } } } else { int f2 = chVar.f(); int f3 = chVar.f(); int i4 = f2 + f3; for (int i5 = 0; i5 < f2; i5++) { chVar.f(); chVar.g(); } for (int i6 = 0; i6 < f3; i6++) { chVar.f(); chVar.g(); } i = i4; } } } private void c() { b1.b(this.c); xp.a(this.d); } public static final class a { private final qo a; private long b; private boolean c; private int d; private long e; private boolean f; private boolean g; private boolean h; private boolean i; private boolean j; private long k; private long l; private boolean m; private static boolean a(int i) { return (32 <= i && i <= 35) || i == 39; } private static boolean b(int i) { return i < 32 || i == 40; } public void a() { this.f = false; this.g = false; this.h = false; this.i = false; this.j = false; } public a(qo qoVar) { this.a = qoVar; } public void a(long j, int i, boolean z) { if (this.j && this.g) { this.m = this.c; this.j = false; } else if (this.h || this.g) { if (z && this.i) { c(i + ((int) (j - this.b))); } this.k = this.b; this.l = this.e; this.m = this.c; this.i = true; } } private void c(int i) { long j = this.l; if (j == C.TIME_UNSET) { return; } boolean z = this.m; this.a.a(j, z ? 1 : 0, (int) (this.b - this.k), i, null); } public void a(byte[] bArr, int i, int i2) { if (this.f) { int i3 = this.d; int i4 = (i + 2) - i3; if (i4 >= i2) { this.d = i3 + (i2 - i); } else { this.g = (bArr[i4] & ByteCompanionObject.MIN_VALUE) != 0; this.f = false; } } } public void a(long j, int i, int i2, long j2, boolean z) { this.g = false; this.h = false; this.e = j2; this.d = 0; this.b = j; if (!b(i2)) { if (this.i && !this.j) { if (z) { c(i); } this.i = false; } if (a(i2)) { this.h = !this.j; this.j = true; } } boolean z2 = i2 >= 16 && i2 <= 21; this.c = z2; this.f = z2 || i2 <= 9; } } private void a(long j, int i, int i2, long j2) { this.d.a(j, i, this.e); if (!this.e) { this.g.a(i2); this.h.a(i2); this.i.a(i2); if (this.g.a() && this.h.a() && this.i.a()) { this.c.a(a(this.b, this.g, this.h, this.i)); this.e = true; } } if (this.j.a(i2)) { yf yfVar = this.j; this.n.a(this.j.d, zf.c(yfVar.d, yfVar.e)); this.n.g(5); this.a.a(j2, this.n); } if (this.k.a(i2)) { yf yfVar2 = this.k; this.n.a(this.k.d, zf.c(yfVar2.d, yfVar2.e)); this.n.g(5); this.a.a(j2, this.n); } } private void b(long j, int i, int i2, long j2) { this.d.a(j, i, i2, j2, this.e); if (!this.e) { this.g.b(i2); this.h.b(i2); this.i.b(i2); } this.j.b(i2); this.k.b(i2); } private void a(byte[] bArr, int i, int i2) { this.d.a(bArr, i, i2); if (!this.e) { this.g.a(bArr, i, i2); this.h.a(bArr, i, i2); this.i.a(bArr, i, i2); } this.j.a(bArr, i, i2); this.k.a(bArr, i, i2); } private static f9 a(String str, yf yfVar, yf yfVar2, yf yfVar3) { int i = yfVar.e; byte[] bArr = new byte[yfVar2.e + i + yfVar3.e]; System.arraycopy(yfVar.d, 0, bArr, 0, i); System.arraycopy(yfVar2.d, 0, bArr, yfVar.e, yfVar2.e); System.arraycopy(yfVar3.d, 0, bArr, yfVar.e + yfVar2.e, yfVar3.e); ch chVar = new ch(yfVar2.d, 0, yfVar2.e); chVar.d(44); int b = chVar.b(3); chVar.g(); chVar.d(88); chVar.d(8); int i2 = 0; for (int i3 = 0; i3 < b; i3++) { if (chVar.c()) { i2 += 89; } if (chVar.c()) { i2 += 8; } } chVar.d(i2); if (b > 0) { chVar.d((8 - b) * 2); } chVar.f(); int f = chVar.f(); if (f == 3) { chVar.g(); } int f2 = chVar.f(); int f3 = chVar.f(); if (chVar.c()) { int f4 = chVar.f(); int f5 = chVar.f(); int f6 = chVar.f(); int f7 = chVar.f(); f2 -= ((f == 1 || f == 2) ? 2 : 1) * (f4 + f5); f3 -= (f == 1 ? 2 : 1) * (f6 + f7); } chVar.f(); chVar.f(); int f8 = chVar.f(); for (int i4 = chVar.c() ? 0 : b; i4 <= b; i4++) { chVar.f(); chVar.f(); chVar.f(); } chVar.f(); chVar.f(); chVar.f(); chVar.f(); chVar.f(); chVar.f(); if (chVar.c() && chVar.c()) { a(chVar); } chVar.d(2); if (chVar.c()) { chVar.d(8); chVar.f(); chVar.f(); chVar.g(); } b(chVar); if (chVar.c()) { for (int i5 = 0; i5 < chVar.f(); i5++) { chVar.d(f8 + 5); } } chVar.d(2); float f9 = 1.0f; if (chVar.c()) { if (chVar.c()) { int b2 = chVar.b(8); if (b2 == 255) { int b3 = chVar.b(16); int b4 = chVar.b(16); if (b3 != 0 && b4 != 0) { f9 = b3 / b4; } } else { float[] fArr = zf.b; if (b2 < fArr.length) { f9 = fArr[b2]; } else { pc.d("H265Reader", "Unexpected aspect_ratio_idc value: " + b2); } } } if (chVar.c()) { chVar.g(); } if (chVar.c()) { chVar.d(4); if (chVar.c()) { chVar.d(24); } } if (chVar.c()) { chVar.f(); chVar.f(); } chVar.g(); if (chVar.c()) { f3 *= 2; } } chVar.a(yfVar2.d, 0, yfVar2.e); chVar.d(24); return new f9.b().c(str).f("video/hevc").a(o3.a(chVar)).q(f2).g(f3).b(f9).a(Collections.singletonList(bArr)).a(); } @Override // com.applovin.impl.q7 public void a() { this.l = 0L; this.m = C.TIME_UNSET; zf.a(this.f); this.g.b(); this.h.b(); this.i.b(); this.j.b(); this.k.b(); a aVar = this.d; if (aVar != null) { aVar.a(); } } private static void a(ch chVar) { for (int i = 0; i < 4; i++) { int i2 = 0; while (i2 < 6) { int i3 = 1; if (!chVar.c()) { chVar.f(); } else { int min = Math.min(64, 1 << ((i << 1) + 4)); if (i > 1) { chVar.e(); } for (int i4 = 0; i4 < min; i4++) { chVar.e(); } } if (i == 3) { i3 = 3; } i2 += i3; } } } }