package com.applovin.impl; import com.applovin.impl.dp; import com.applovin.impl.f9; import com.mbridge.msdk.playercommon.exoplayer2.C; import com.mbridge.msdk.playercommon.exoplayer2.extractor.ts.PsExtractor; import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes; import java.util.Arrays; import java.util.Collections; /* loaded from: classes.dex */ public final class ga implements q7 { private static final float[] l = {1.0f, 1.0f, 1.0909091f, 0.90909094f, 1.4545455f, 1.2121212f, 1.0f}; private final vp a; private final bh b; private final yf e; private b f; private long g; private String h; private qo i; private boolean j; private final boolean[] c = new boolean[4]; private final a d = new a(128); private long k = C.TIME_UNSET; @Override // com.applovin.impl.q7 public void a(long j, int i) { if (j != C.TIME_UNSET) { this.k = j; } } @Override // com.applovin.impl.q7 public void b() { } public ga(vp vpVar) { this.a = vpVar; if (vpVar != null) { this.e = new yf(178, 128); this.b = new bh(); } else { this.e = null; this.b = null; } } @Override // com.applovin.impl.q7 public void a(bh bhVar) { b1.b(this.f); b1.b(this.i); int d = bhVar.d(); int e = bhVar.e(); byte[] c = bhVar.c(); this.g += bhVar.a(); this.i.a(bhVar, bhVar.a()); while (true) { int a2 = zf.a(c, d, e, this.c); if (a2 == e) { break; } int i = a2 + 3; int i2 = bhVar.c()[i] & 255; int i3 = a2 - d; int i4 = 0; if (!this.j) { if (i3 > 0) { this.d.a(c, d, a2); } if (this.d.a(i2, i3 < 0 ? -i3 : 0)) { qo qoVar = this.i; a aVar = this.d; qoVar.a(a(aVar, aVar.d, (String) b1.a((Object) this.h))); this.j = true; } } this.f.a(c, d, a2); yf yfVar = this.e; if (yfVar != null) { if (i3 > 0) { yfVar.a(c, d, a2); } else { i4 = -i3; } if (this.e.a(i4)) { yf yfVar2 = this.e; ((bh) xp.a(this.b)).a(this.e.d, zf.c(yfVar2.d, yfVar2.e)); ((vp) xp.a(this.a)).a(this.k, this.b); } if (i2 == 178 && bhVar.c()[a2 + 2] == 1) { this.e.b(i2); } } int i5 = e - a2; this.f.a(this.g - i5, i5, this.j); this.f.a(i2, this.k); d = i; } if (!this.j) { this.d.a(c, d, e); } this.f.a(c, d, e); yf yfVar3 = this.e; if (yfVar3 != null) { yfVar3.a(c, d, e); } } @Override // com.applovin.impl.q7 public void a(m8 m8Var, dp.d dVar) { dVar.a(); this.h = dVar.b(); qo a2 = m8Var.a(dVar.c(), 2); this.i = a2; this.f = new b(a2); vp vpVar = this.a; if (vpVar != null) { vpVar.a(m8Var, dVar); } } public static final class a { private static final byte[] f = {0, 0, 1}; private boolean a; private int b; public int c; public int d; public byte[] e; public void a() { this.a = false; this.c = 0; this.b = 0; } public a(int i) { this.e = new byte[i]; } public void a(byte[] bArr, int i, int i2) { if (this.a) { int i3 = i2 - i; byte[] bArr2 = this.e; int length = bArr2.length; int i4 = this.c + i3; if (length < i4) { this.e = Arrays.copyOf(bArr2, i4 * 2); } System.arraycopy(bArr, i, this.e, this.c, i3); this.c += i3; } } public boolean a(int i, int i2) { int i3 = this.b; if (i3 != 0) { if (i3 != 1) { if (i3 != 2) { if (i3 != 3) { if (i3 != 4) { throw new IllegalStateException(); } if (i == 179 || i == 181) { this.c -= i2; this.a = false; return true; } } else if ((i & PsExtractor.VIDEO_STREAM_MASK) != 32) { pc.d("H263Reader", "Unexpected start code value"); a(); } else { this.d = this.c; this.b = 4; } } else if (i > 31) { pc.d("H263Reader", "Unexpected start code value"); a(); } else { this.b = 3; } } else if (i != 181) { pc.d("H263Reader", "Unexpected start code value"); a(); } else { this.b = 2; } } else if (i == 176) { this.b = 1; this.a = true; } byte[] bArr = f; a(bArr, 0, bArr.length); return false; } } public static final class b { private final qo a; private boolean b; private boolean c; private boolean d; private int e; private int f; private long g; private long h; public void a() { this.b = false; this.c = false; this.d = false; this.e = -1; } public void a(int i, long j) { this.e = i; this.d = false; this.b = i == 182 || i == 179; this.c = i == 182; this.f = 0; this.h = j; } public b(qo qoVar) { this.a = qoVar; } public void a(byte[] bArr, int i, int i2) { if (this.c) { int i3 = this.f; int i4 = (i + 1) - i3; if (i4 >= i2) { this.f = i3 + (i2 - i); } else { this.d = ((bArr[i4] & 192) >> 6) == 0; this.c = false; } } } public void a(long j, int i, boolean z) { if (this.e == 182 && z && this.b) { long j2 = this.h; if (j2 != C.TIME_UNSET) { this.a.a(j2, this.d ? 1 : 0, (int) (j - this.g), i, null); } } if (this.e != 179) { this.g = j; } } } private static f9 a(a aVar, int i, String str) { byte[] copyOf = Arrays.copyOf(aVar.e, aVar.c); ah ahVar = new ah(copyOf); ahVar.e(i); ahVar.e(4); ahVar.g(); ahVar.d(8); if (ahVar.f()) { ahVar.d(4); ahVar.d(3); } int a2 = ahVar.a(4); float f = 1.0f; if (a2 == 15) { int a3 = ahVar.a(8); int a4 = ahVar.a(8); if (a4 == 0) { pc.d("H263Reader", "Invalid aspect ratio"); } else { f = a3 / a4; } } else { float[] fArr = l; if (a2 < fArr.length) { f = fArr[a2]; } else { pc.d("H263Reader", "Invalid aspect ratio"); } } if (ahVar.f()) { ahVar.d(2); ahVar.d(1); if (ahVar.f()) { ahVar.d(15); ahVar.g(); ahVar.d(15); ahVar.g(); ahVar.d(15); ahVar.g(); ahVar.d(3); ahVar.d(11); ahVar.g(); ahVar.d(15); ahVar.g(); } } if (ahVar.a(2) != 0) { pc.d("H263Reader", "Unhandled video object layer shape"); } ahVar.g(); int a5 = ahVar.a(16); ahVar.g(); if (ahVar.f()) { if (a5 == 0) { pc.d("H263Reader", "Invalid vop_increment_time_resolution"); } else { int i2 = 0; for (int i3 = a5 - 1; i3 > 0; i3 >>= 1) { i2++; } ahVar.d(i2); } } ahVar.g(); int a6 = ahVar.a(13); ahVar.g(); int a7 = ahVar.a(13); ahVar.g(); ahVar.g(); return new f9.b().c(str).f(MimeTypes.VIDEO_MP4V).q(a6).g(a7).b(f).a(Collections.singletonList(copyOf)).a(); } @Override // com.applovin.impl.q7 public void a() { zf.a(this.c); this.d.a(); b bVar = this.f; if (bVar != null) { bVar.a(); } yf yfVar = this.e; if (yfVar != null) { yfVar.b(); } this.g = 0L; this.k = C.TIME_UNSET; } }