package com.applovin.impl; import com.applovin.impl.bf; import com.applovin.impl.f9; import com.applovin.impl.ij; import com.mbridge.msdk.playercommon.exoplayer2.C; /* loaded from: classes.dex */ public final class yb implements k8 { private m8 b; private int c; private int d; private int e; private nf g; private l8 h; private dl i; private pf j; private final bh a = new bh(6); private long f = -1; @Override // com.applovin.impl.k8 public void a(m8 m8Var) { this.b = m8Var; } private int c(l8 l8Var) { this.a.d(2); l8Var.c(this.a.c(), 0, 2); return this.a.C(); } private void b(l8 l8Var) { this.a.d(2); l8Var.c(this.a.c(), 0, 2); l8Var.c(this.a.C() - 2); } private void d(l8 l8Var) { this.a.d(2); l8Var.d(this.a.c(), 0, 2); int C = this.a.C(); this.d = C; if (C == 65498) { if (this.f != -1) { this.c = 4; return; } else { b(); return; } } if ((C < 65488 || C > 65497) && C != 65281) { this.c = 1; } } private void f(l8 l8Var) { this.a.d(2); l8Var.d(this.a.c(), 0, 2); this.e = this.a.C() - 2; this.c = 2; } private void e(l8 l8Var) { String t; if (this.d == 65505) { bh bhVar = new bh(this.e); l8Var.d(bhVar.c(), 0, this.e); if (this.g == null && "http://ns.adobe.com/xap/1.0/".equals(bhVar.t()) && (t = bhVar.t()) != null) { nf a = a(t, l8Var.a()); this.g = a; if (a != null) { this.f = a.d; } } } else { l8Var.a(this.e); } this.c = 0; } private void g(l8 l8Var) { if (!l8Var.b(this.a.c(), 0, 1, true)) { b(); return; } l8Var.b(); if (this.j == null) { this.j = new pf(); } dl dlVar = new dl(l8Var, this.f); this.i = dlVar; if (this.j.a(dlVar)) { this.j.a(new el(this.f, (m8) b1.a(this.b))); c(); } else { b(); } } private static nf a(String str, long j) { mf a; if (j == -1 || (a = hs.a(str)) == null) { return null; } return a.a(j); } private void c() { a((bf.b) b1.a(this.g)); this.c = 5; } private void b() { a(new bf.b[0]); ((m8) b1.a(this.b)).c(); this.b.a(new ij.b(C.TIME_UNSET)); this.c = 6; } private void a(bf.b... bVarArr) { ((m8) b1.a(this.b)).a(1024, 4).a(new f9.b().b("image/jpeg").a(new bf(bVarArr)).a()); } @Override // com.applovin.impl.k8 public int a(l8 l8Var, th thVar) { int i = this.c; if (i == 0) { d(l8Var); return 0; } if (i == 1) { f(l8Var); return 0; } if (i == 2) { e(l8Var); return 0; } if (i == 4) { long f = l8Var.f(); long j = this.f; if (f != j) { thVar.a = j; return 1; } g(l8Var); return 0; } if (i != 5) { if (i == 6) { return -1; } throw new IllegalStateException(); } if (this.i == null || l8Var != this.h) { this.h = l8Var; this.i = new dl(l8Var, this.f); } int a = ((pf) b1.a(this.j)).a(this.i, thVar); if (a == 1) { thVar.a += this.f; } return a; } @Override // com.applovin.impl.k8 public void a() { pf pfVar = this.j; if (pfVar != null) { pfVar.a(); } } @Override // com.applovin.impl.k8 public void a(long j, long j2) { if (j == 0) { this.c = 0; this.j = null; } else if (this.c == 5) { ((pf) b1.a(this.j)).a(j, j2); } } @Override // com.applovin.impl.k8 public boolean a(l8 l8Var) { if (c(l8Var) != 65496) { return false; } int c = c(l8Var); this.d = c; if (c == 65504) { b(l8Var); this.d = c(l8Var); } if (this.d != 65505) { return false; } l8Var.c(2); this.a.d(6); l8Var.c(this.a.c(), 0, 6); return this.a.y() == 1165519206 && this.a.C() == 0; } }