package androidx.media3.exoplayer.upstream; import android.net.Uri; import androidx.media3.common.util.Assertions; import androidx.media3.common.util.Util; import androidx.media3.datasource.DataSource; import androidx.media3.datasource.DataSourceInputStream; import androidx.media3.datasource.DataSpec; import androidx.media3.datasource.StatsDataSource; import androidx.media3.exoplayer.source.LoadEventInfo; import androidx.media3.exoplayer.upstream.Loader; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ public final class ParsingLoadable implements Loader.Loadable { private final StatsDataSource dataSource; public final DataSpec dataSpec; public final long loadTaskId; private final Parser parser; private volatile T result; public final int type; /* loaded from: classes2.dex */ public interface Parser { T parse(Uri uri, InputStream inputStream) throws IOException; } @Override // androidx.media3.exoplayer.upstream.Loader.Loadable public final void cancelLoad() { } public final T getResult() { return this.result; } public static T load(DataSource dataSource, Parser parser, Uri uri, int i) throws IOException { ParsingLoadable parsingLoadable = new ParsingLoadable(dataSource, uri, i, parser); parsingLoadable.load(); return (T) Assertions.checkNotNull(parsingLoadable.getResult()); } public static T load(DataSource dataSource, Parser parser, DataSpec dataSpec, int i) throws IOException { ParsingLoadable parsingLoadable = new ParsingLoadable(dataSource, dataSpec, i, parser); parsingLoadable.load(); return (T) Assertions.checkNotNull(parsingLoadable.getResult()); } public ParsingLoadable(DataSource dataSource, Uri uri, int i, Parser parser) { this(dataSource, new DataSpec.Builder().setUri(uri).setFlags(1).build(), i, parser); } public ParsingLoadable(DataSource dataSource, DataSpec dataSpec, int i, Parser parser) { this.dataSource = new StatsDataSource(dataSource); this.dataSpec = dataSpec; this.type = i; this.parser = parser; this.loadTaskId = LoadEventInfo.getNewId(); } public long bytesLoaded() { return this.dataSource.getBytesRead(); } public Uri getUri() { return this.dataSource.getLastOpenedUri(); } public Map> getResponseHeaders() { return this.dataSource.getLastResponseHeaders(); } @Override // androidx.media3.exoplayer.upstream.Loader.Loadable public final void load() throws IOException { this.dataSource.resetBytesRead(); DataSourceInputStream dataSourceInputStream = new DataSourceInputStream(this.dataSource, this.dataSpec); try { dataSourceInputStream.open(); this.result = this.parser.parse((Uri) Assertions.checkNotNull(this.dataSource.getUri()), dataSourceInputStream); } finally { Util.closeQuietly(dataSourceInputStream); } } }