package p6; import d6.r0; import e7.b; import f8.y; import l6.i; import l6.j; import l6.k; import l6.x; import l6.y; import y6.a; /* compiled from: JpegExtractor.java */ /* loaded from: classes4.dex */ public final class a implements i { /* renamed from: b reason: collision with root package name */ private k f19973b; /* renamed from: c reason: collision with root package name */ private int f19974c; /* renamed from: d reason: collision with root package name */ private int f19975d; /* renamed from: e reason: collision with root package name */ private int f19976e; /* renamed from: g reason: collision with root package name */ private b f19978g; /* renamed from: h reason: collision with root package name */ private j f19979h; /* renamed from: i reason: collision with root package name */ private c f19980i; /* renamed from: j reason: collision with root package name */ private s6.k f19981j; /* renamed from: a reason: collision with root package name */ private final y f19972a = new y(6); /* renamed from: f reason: collision with root package name */ private long f19977f = -1; private void a(j jVar) { this.f19972a.L(2); jVar.q(this.f19972a.d(), 0, 2); jVar.i(this.f19972a.J() - 2); } private void d() { h(new a.b[0]); ((k) f8.a.e(this.f19973b)).p(); this.f19973b.r(new y.b(-9223372036854775807L)); this.f19974c = 6; } private static b e(String str, long j10) { b a10; if (j10 == -1 || (a10 = e.a(str)) == null) { return null; } return a10.a(j10); } private void h(a.b... bVarArr) { ((k) f8.a.e(this.f19973b)).e(1024, 4).a(new r0.b().X(new y6.a(bVarArr)).E()); } private int i(j jVar) { this.f19972a.L(2); jVar.q(this.f19972a.d(), 0, 2); return this.f19972a.J(); } private void j(j jVar) { this.f19972a.L(2); jVar.readFully(this.f19972a.d(), 0, 2); int J = this.f19972a.J(); this.f19975d = J; if (J == 65498) { if (this.f19977f != -1) { this.f19974c = 4; } else { d(); } } else if ((J < 65488 || J > 65497) && J != 65281) { this.f19974c = 1; } } private void k(j jVar) { String x10; if (this.f19975d == 65505) { f8.y yVar = new f8.y(this.f19976e); jVar.readFully(yVar.d(), 0, this.f19976e); if (this.f19978g == null && "http://ns.adobe.com/xap/1.0/".equals(yVar.x()) && (x10 = yVar.x()) != null) { b e10 = e(x10, jVar.a()); this.f19978g = e10; if (e10 != null) { this.f19977f = e10.f10666m; } } } else { jVar.n(this.f19976e); } this.f19974c = 0; } private void l(j jVar) { this.f19972a.L(2); jVar.readFully(this.f19972a.d(), 0, 2); this.f19976e = this.f19972a.J() - 2; this.f19974c = 2; } private void m(j jVar) { if (!jVar.g(this.f19972a.d(), 0, 1, true)) { d(); return; } jVar.m(); if (this.f19981j == null) { this.f19981j = new s6.k(); } c cVar = new c(jVar, this.f19977f); this.f19980i = cVar; if (this.f19981j.g(cVar)) { this.f19981j.c(new d(this.f19977f, (k) f8.a.e(this.f19973b))); n(); return; } d(); } private void n() { h((a.b) f8.a.e(this.f19978g)); this.f19974c = 5; } @Override // l6.i public void b(long j10, long j11) { if (j10 == 0) { this.f19974c = 0; this.f19981j = null; } else if (this.f19974c == 5) { ((s6.k) f8.a.e(this.f19981j)).b(j10, j11); } } @Override // l6.i public void c(k kVar) { this.f19973b = kVar; } @Override // l6.i public int f(j jVar, x xVar) { int i10 = this.f19974c; if (i10 == 0) { j(jVar); return 0; } else if (i10 == 1) { l(jVar); return 0; } else if (i10 == 2) { k(jVar); return 0; } else if (i10 == 4) { long d10 = jVar.d(); long j10 = this.f19977f; if (d10 != j10) { xVar.f16517a = j10; return 1; } m(jVar); return 0; } else if (i10 == 5) { if (this.f19980i == null || jVar != this.f19979h) { this.f19979h = jVar; this.f19980i = new c(jVar, this.f19977f); } int f2 = ((s6.k) f8.a.e(this.f19981j)).f(this.f19980i, xVar); if (f2 == 1) { xVar.f16517a += this.f19977f; } return f2; } else if (i10 == 6) { return -1; } else { throw new IllegalStateException(); } } @Override // l6.i public boolean g(j jVar) { if (i(jVar) != 65496) { return false; } int i10 = i(jVar); this.f19975d = i10; if (i10 == 65504) { a(jVar); this.f19975d = i(jVar); } if (this.f19975d != 65505) { return false; } jVar.i(2); this.f19972a.L(6); jVar.q(this.f19972a.d(), 0, 6); return this.f19972a.F() == 1165519206 && this.f19972a.J() == 0; } @Override // l6.i public void release() { s6.k kVar = this.f19981j; if (kVar != null) { kVar.release(); } } }