package s1; import android.util.Log; import com.bumptech.glide.load.data.d; import java.util.Collections; import java.util.List; import s1.f; import w1.m; /* loaded from: classes.dex */ class z implements f, f.a { /* renamed from: a, reason: collision with root package name */ private final g f13987a; /* renamed from: b, reason: collision with root package name */ private final f.a f13988b; /* renamed from: c, reason: collision with root package name */ private int f13989c; /* renamed from: d, reason: collision with root package name */ private c f13990d; /* renamed from: e, reason: collision with root package name */ private Object f13991e; /* renamed from: f, reason: collision with root package name */ private volatile m.a f13992f; /* renamed from: g, reason: collision with root package name */ private d f13993g; class a implements d.a { /* renamed from: a, reason: collision with root package name */ final /* synthetic */ m.a f13994a; a(m.a aVar) { this.f13994a = aVar; } @Override // com.bumptech.glide.load.data.d.a public void c(Exception exc) { if (z.this.g(this.f13994a)) { z.this.i(this.f13994a, exc); } } @Override // com.bumptech.glide.load.data.d.a public void e(Object obj) { if (z.this.g(this.f13994a)) { z.this.h(this.f13994a, obj); } } } z(g gVar, f.a aVar) { this.f13987a = gVar; this.f13988b = aVar; } private void c(Object obj) { long b10 = m2.f.b(); try { q1.d p10 = this.f13987a.p(obj); e eVar = new e(p10, obj, this.f13987a.k()); this.f13993g = new d(this.f13992f.f15056a, this.f13987a.o()); this.f13987a.d().a(this.f13993g, eVar); if (Log.isLoggable("SourceGenerator", 2)) { Log.v("SourceGenerator", "Finished encoding source to cache, key: " + this.f13993g + ", data: " + obj + ", encoder: " + p10 + ", duration: " + m2.f.a(b10)); } this.f13992f.f15058c.b(); this.f13990d = new c(Collections.singletonList(this.f13992f.f15056a), this.f13987a, this); } catch (Throwable th) { this.f13992f.f15058c.b(); throw th; } } private boolean f() { return this.f13989c < this.f13987a.g().size(); } private void j(m.a aVar) { this.f13992f.f15058c.f(this.f13987a.l(), new a(aVar)); } @Override // s1.f.a public void a(q1.f fVar, Object obj, com.bumptech.glide.load.data.d dVar, q1.a aVar, q1.f fVar2) { this.f13988b.a(fVar, obj, dVar, this.f13992f.f15058c.d(), fVar); } @Override // s1.f.a public void b() { throw new UnsupportedOperationException(); } @Override // s1.f public void cancel() { m.a aVar = this.f13992f; if (aVar != null) { aVar.f15058c.cancel(); } } @Override // s1.f public boolean d() { Object obj = this.f13991e; if (obj != null) { this.f13991e = null; c(obj); } c cVar = this.f13990d; if (cVar != null && cVar.d()) { return true; } this.f13990d = null; this.f13992f = null; boolean z10 = false; while (!z10 && f()) { List g10 = this.f13987a.g(); int i10 = this.f13989c; this.f13989c = i10 + 1; this.f13992f = (m.a) g10.get(i10); if (this.f13992f != null && (this.f13987a.e().c(this.f13992f.f15058c.d()) || this.f13987a.t(this.f13992f.f15058c.a()))) { j(this.f13992f); z10 = true; } } return z10; } @Override // s1.f.a public void e(q1.f fVar, Exception exc, com.bumptech.glide.load.data.d dVar, q1.a aVar) { this.f13988b.e(fVar, exc, dVar, this.f13992f.f15058c.d()); } boolean g(m.a aVar) { m.a aVar2 = this.f13992f; return aVar2 != null && aVar2 == aVar; } void h(m.a aVar, Object obj) { j e10 = this.f13987a.e(); if (obj != null && e10.c(aVar.f15058c.d())) { this.f13991e = obj; this.f13988b.b(); } else { f.a aVar2 = this.f13988b; q1.f fVar = aVar.f15056a; com.bumptech.glide.load.data.d dVar = aVar.f15058c; aVar2.a(fVar, obj, dVar, dVar.d(), this.f13993g); } } void i(m.a aVar, Exception exc) { f.a aVar2 = this.f13988b; d dVar = this.f13993g; com.bumptech.glide.load.data.d dVar2 = aVar.f15058c; aVar2.e(dVar, exc, dVar2, dVar2.d()); } }