package c6; import java.io.IOException; import k6.a; import q6.b; import q7.b0; import s5.m1; import x5.k; import x5.l; import x5.m; import x5.y; import x5.z; public final class a implements k { /* renamed from: a reason: collision with root package name */ private final b0 f5330a = new b0(6); /* renamed from: b reason: collision with root package name */ private m f5331b; /* renamed from: c reason: collision with root package name */ private int f5332c; /* renamed from: d reason: collision with root package name */ private int f5333d; /* renamed from: e reason: collision with root package name */ private int f5334e; /* renamed from: f reason: collision with root package name */ private long f5335f = -1; /* renamed from: g reason: collision with root package name */ private b f5336g; /* renamed from: h reason: collision with root package name */ private l f5337h; /* renamed from: i reason: collision with root package name */ private c f5338i; /* renamed from: j reason: collision with root package name */ private f6.k f5339j; private void a(l lVar) throws IOException { this.f5330a.K(2); lVar.p(this.f5330a.d(), 0, 2); lVar.i(this.f5330a.I() - 2); } private void e() { h(new a.b[0]); ((m) q7.a.e(this.f5331b)).k(); this.f5331b.n(new z.b(-9223372036854775807L)); this.f5332c = 6; } private static b f(String str, long j10) throws IOException { b a10; if (j10 == -1 || (a10 = e.a(str)) == null) { return null; } return a10.a(j10); } private void h(a.b... bVarArr) { ((m) q7.a.e(this.f5331b)).e(1024, 4).b(new m1.b().K("image/jpeg").X(new k6.a(bVarArr)).E()); } private int i(l lVar) throws IOException { this.f5330a.K(2); lVar.p(this.f5330a.d(), 0, 2); return this.f5330a.I(); } private void j(l lVar) throws IOException { int i10; this.f5330a.K(2); lVar.readFully(this.f5330a.d(), 0, 2); int I = this.f5330a.I(); this.f5333d = I; if (I == 65498) { if (this.f5335f != -1) { i10 = 4; } else { e(); return; } } else if ((I < 65488 || I > 65497) && I != 65281) { i10 = 1; } else { return; } this.f5332c = i10; } private void k(l lVar) throws IOException { String w10; if (this.f5333d == 65505) { b0 b0Var = new b0(this.f5334e); lVar.readFully(b0Var.d(), 0, this.f5334e); if (this.f5336g == null && "http://ns.adobe.com/xap/1.0/".equals(b0Var.w()) && (w10 = b0Var.w()) != null) { b f10 = f(w10, lVar.b()); this.f5336g = f10; if (f10 != null) { this.f5335f = f10.f23113d; } } } else { lVar.m(this.f5334e); } this.f5332c = 0; } private void l(l lVar) throws IOException { this.f5330a.K(2); lVar.readFully(this.f5330a.d(), 0, 2); this.f5334e = this.f5330a.I() - 2; this.f5332c = 2; } private void m(l lVar) throws IOException { if (lVar.g(this.f5330a.d(), 0, 1, true)) { lVar.l(); if (this.f5339j == null) { this.f5339j = new f6.k(); } c cVar = new c(lVar, this.f5335f); this.f5338i = cVar; if (this.f5339j.d(cVar)) { this.f5339j.b(new d(this.f5335f, (m) q7.a.e(this.f5331b))); n(); return; } } e(); } private void n() { h((a.b) q7.a.e(this.f5336g)); this.f5332c = 5; } @Override // x5.k public void b(m mVar) { this.f5331b = mVar; } @Override // x5.k public void c(long j10, long j11) { if (j10 == 0) { this.f5332c = 0; this.f5339j = null; } else if (this.f5332c == 5) { ((f6.k) q7.a.e(this.f5339j)).c(j10, j11); } } @Override // x5.k public boolean d(l lVar) throws IOException { if (i(lVar) != 65496) { return false; } int i10 = i(lVar); this.f5333d = i10; if (i10 == 65504) { a(lVar); this.f5333d = i(lVar); } if (this.f5333d != 65505) { return false; } lVar.i(2); this.f5330a.K(6); lVar.p(this.f5330a.d(), 0, 6); return this.f5330a.E() == 1165519206 && this.f5330a.I() == 0; } @Override // x5.k public int g(l lVar, y yVar) throws IOException { int i10 = this.f5332c; if (i10 == 0) { j(lVar); return 0; } else if (i10 == 1) { l(lVar); return 0; } else if (i10 == 2) { k(lVar); return 0; } else if (i10 == 4) { long position = lVar.getPosition(); long j10 = this.f5335f; if (position != j10) { yVar.f29152a = j10; return 1; } m(lVar); return 0; } else if (i10 == 5) { if (this.f5338i == null || lVar != this.f5337h) { this.f5337h = lVar; this.f5338i = new c(lVar, this.f5335f); } int g10 = ((f6.k) q7.a.e(this.f5339j)).g(this.f5338i, yVar); if (g10 == 1) { yVar.f29152a += this.f5335f; } return g10; } else if (i10 == 6) { return -1; } else { throw new IllegalStateException(); } } @Override // x5.k public void release() { f6.k kVar = this.f5339j; if (kVar != null) { kVar.release(); } } }