package com.bumptech.glide.load.engine; import android.util.Log; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.Encoder; import com.bumptech.glide.load.Key; import com.bumptech.glide.load.data.DataFetcher; import com.bumptech.glide.load.engine.DataFetcherGenerator; import com.bumptech.glide.load.model.ModelLoader; import com.bumptech.glide.util.LogTime; import java.util.Collections; import java.util.List; /* loaded from: classes.dex */ class SourceGenerator implements DataFetcherGenerator, DataFetcher.DataCallback, DataFetcherGenerator.FetcherReadyCallback { private final DecodeHelper a; private final DataFetcherGenerator.FetcherReadyCallback b; private int c; private DataCacheGenerator d; private Object e; private volatile ModelLoader.LoadData f; private DataCacheKey g; SourceGenerator(DecodeHelper decodeHelper, DataFetcherGenerator.FetcherReadyCallback fetcherReadyCallback) { this.a = decodeHelper; this.b = fetcherReadyCallback; } private boolean b() { return this.c < this.a.g().size(); } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator public boolean a() { Object obj = this.e; if (obj != null) { this.e = null; b(obj); } DataCacheGenerator dataCacheGenerator = this.d; if (dataCacheGenerator != null && dataCacheGenerator.a()) { return true; } this.d = null; this.f = null; boolean z = false; while (!z && b()) { List> g = this.a.g(); int i = this.c; this.c = i + 1; this.f = g.get(i); if (this.f != null && (this.a.e().a(this.f.c.getDataSource()) || this.a.c(this.f.c.a()))) { this.f.c.a(this.a.i(), this); z = true; } } return z; } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator public void cancel() { ModelLoader.LoadData loadData = this.f; if (loadData != null) { loadData.c.cancel(); } } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void d() { throw new UnsupportedOperationException(); } private void b(Object obj) { long a = LogTime.a(); try { Encoder a2 = this.a.a((DecodeHelper) obj); DataCacheWriter dataCacheWriter = new DataCacheWriter(a2, obj, this.a.h()); this.g = new DataCacheKey(this.f.a, this.a.k()); this.a.d().a(this.g, dataCacheWriter); if (Log.isLoggable("SourceGenerator", 2)) { Log.v("SourceGenerator", "Finished encoding source to cache, key: " + this.g + ", data: " + obj + ", encoder: " + a2 + ", duration: " + LogTime.a(a)); } this.f.c.b(); this.d = new DataCacheGenerator(Collections.singletonList(this.f.a), this.a, this); } catch (Throwable th) { this.f.c.b(); throw th; } } @Override // com.bumptech.glide.load.data.DataFetcher.DataCallback public void a(Object obj) { DiskCacheStrategy e = this.a.e(); if (obj != null && e.a(this.f.c.getDataSource())) { this.e = obj; this.b.d(); } else { this.b.a(this.f.a, obj, this.f.c, this.f.c.getDataSource(), this.g); } } @Override // com.bumptech.glide.load.data.DataFetcher.DataCallback public void a(Exception exc) { this.b.a(this.g, exc, this.f.c, this.f.c.getDataSource()); } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void a(Key key, Object obj, DataFetcher dataFetcher, DataSource dataSource, Key key2) { this.b.a(key, obj, dataFetcher, this.f.c.getDataSource(), key); } @Override // com.bumptech.glide.load.engine.DataFetcherGenerator.FetcherReadyCallback public void a(Key key, Exception exc, DataFetcher dataFetcher, DataSource dataSource) { this.b.a(key, exc, dataFetcher, this.f.c.getDataSource()); } }