package com.applovin.impl; import com.applovin.impl.dp; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ public final class ih implements dp { private final q7 a; private final ah b = new ah(new byte[10]); private int c = 0; private int d; private ho e; private boolean f; private boolean g; private boolean h; private int i; private int j; private boolean k; private long l; private void a(int i) { this.c = i; this.d = 0; } public ih(q7 q7Var) { this.a = q7Var; } @Override // com.applovin.impl.dp public final void a(bh bhVar, int i) { b1.b(this.e); if ((i & 1) != 0) { int i2 = this.c; if (i2 != 0 && i2 != 1) { if (i2 == 2) { pc.d("PesReader", "Unexpected start indicator reading extended header"); } else { if (i2 != 3) { throw new IllegalStateException(); } if (this.j != -1) { pc.d("PesReader", "Unexpected start indicator: expected " + this.j + " more bytes"); } this.a.b(); } } a(1); } while (bhVar.a() > 0) { int i3 = this.c; if (i3 != 0) { if (i3 != 1) { if (i3 == 2) { if (a(bhVar, this.b.a, Math.min(10, this.i)) && a(bhVar, (byte[]) null, this.i)) { c(); i |= this.k ? 4 : 0; this.a.a(this.l, i); a(3); } } else { if (i3 != 3) { throw new IllegalStateException(); } int a = bhVar.a(); int i4 = this.j; int i5 = i4 != -1 ? a - i4 : 0; if (i5 > 0) { a -= i5; bhVar.e(bhVar.d() + a); } this.a.a(bhVar); int i6 = this.j; if (i6 != -1) { int i7 = i6 - a; this.j = i7; if (i7 == 0) { this.a.b(); a(1); } } } } else if (a(bhVar, this.b.a, 9)) { a(b() ? 2 : 0); } } else { bhVar.g(bhVar.a()); } } } private boolean b() { this.b.c(0); int a = this.b.a(24); if (a != 1) { pc.d("PesReader", "Unexpected start code prefix: " + a); this.j = -1; return false; } this.b.d(8); int a2 = this.b.a(16); this.b.d(5); this.k = this.b.f(); this.b.d(2); this.f = this.b.f(); this.g = this.b.f(); this.b.d(6); int a3 = this.b.a(8); this.i = a3; if (a2 == 0) { this.j = -1; } else { int i = (a2 - 3) - a3; this.j = i; if (i < 0) { pc.d("PesReader", "Found negative packet payload size: " + this.j); this.j = -1; } } return true; } private void c() { this.b.c(0); this.l = C.TIME_UNSET; if (this.f) { this.b.d(4); this.b.d(1); this.b.d(1); long a = (this.b.a(3) << 30) | (this.b.a(15) << 15) | this.b.a(15); this.b.d(1); if (!this.h && this.g) { this.b.d(4); this.b.d(1); this.b.d(1); this.b.d(1); this.e.b((this.b.a(3) << 30) | (this.b.a(15) << 15) | this.b.a(15)); this.h = true; } this.l = this.e.b(a); } } private boolean a(bh bhVar, byte[] bArr, int i) { int min = Math.min(bhVar.a(), i - this.d); if (min <= 0) { return true; } if (bArr == null) { bhVar.g(min); } else { bhVar.a(bArr, this.d, min); } int i2 = this.d + min; this.d = i2; return i2 == i; } @Override // com.applovin.impl.dp public void a(ho hoVar, m8 m8Var, dp.d dVar) { this.e = hoVar; this.a.a(m8Var, dVar); } @Override // com.applovin.impl.dp public final void a() { this.c = 0; this.d = 0; this.h = false; this.a.a(); } }