package androidx.media3.exoplayer.source;

import android.net.Uri;
import androidx.annotation.Nullable;
import androidx.media3.common.DataReader;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.b0;
import androidx.media3.extractor.e0;
import androidx.media3.extractor.r;
import androidx.media3.extractor.r0;
import androidx.media3.extractor.y;
import androidx.media3.extractor.z;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.m0;
import com.google.common.collect.z0;
import java.io.EOFException;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public final class BundledExtractorsAdapter implements ProgressiveMediaExtractor {

    @Nullable
    private y extractor;

    @Nullable
    private z extractorInput;
    private final e0 extractorsFactory;

    public BundledExtractorsAdapter(e0 e0Var) {
        this.extractorsFactory = e0Var;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static /* synthetic */ String lambda$init$0(y yVar) {
        return yVar.getUnderlyingImplementation().getClass().getSimpleName();
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public void disableSeekingOnMp3Streams() {
        y yVar = this.extractor;
        if (yVar == null) {
            return;
        }
        y underlyingImplementation = yVar.getUnderlyingImplementation();
        if (underlyingImplementation instanceof k2.d) {
            ((k2.d) underlyingImplementation).f29042r = true;
        }
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public long getCurrentInputPosition() {
        z zVar = this.extractorInput;
        if (zVar != null) {
            return zVar.getPosition();
        }
        return -1L;
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public void init(DataReader dataReader, Uri uri, Map<String, List<String>> map, long j10, long j11, b0 b0Var) throws IOException {
        boolean z10;
        r rVar = new r(dataReader, j10, j11);
        this.extractorInput = rVar;
        if (this.extractor != null) {
            return;
        }
        y[] yVarArrC = this.extractorsFactory.c(uri, map);
        m0 m0VarO = ImmutableList.o(yVarArrC.length);
        boolean z11 = true;
        z11 = true;
        if (yVarArrC.length == 1) {
            this.extractor = yVarArrC[0];
        } else {
            int length = yVarArrC.length;
            int i10 = 0;
            while (true) {
                if (i10 >= length) {
                    break;
                }
                y yVar = yVarArrC[i10];
                try {
                    if (yVar.sniff(rVar)) {
                        this.extractor = yVar;
                        Assertions.checkState(true);
                        rVar.f3461f = 0;
                        break;
                    }
                    m0VarO.f(yVar.getSniffFailureDetails());
                    z10 = this.extractor != null || rVar.f3459d == j10;
                } catch (EOFException unused) {
                    z10 = this.extractor != null || rVar.f3459d == j10;
                } catch (Throwable th) {
                    if (this.extractor == null && rVar.f3459d != j10) {
                        z11 = false;
                    }
                    Assertions.checkState(z11);
                    rVar.f3461f = 0;
                    throw th;
                }
                Assertions.checkState(z10);
                rVar.f3461f = 0;
                i10++;
            }
            if (this.extractor == null) {
                throw new UnrecognizedInputFormatException("None of the available extractors (" + new com.google.common.base.f(", ").b(z0.B(ImmutableList.r(yVarArrC), new h(z11 ? 1 : 0))) + ") could read the stream.", (Uri) Assertions.checkNotNull(uri), m0VarO.i());
            }
        }
        this.extractor.init(b0Var);
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public int read(r0 r0Var) throws IOException {
        return ((y) Assertions.checkNotNull(this.extractor)).read((z) Assertions.checkNotNull(this.extractorInput), r0Var);
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public void release() {
        y yVar = this.extractor;
        if (yVar != null) {
            yVar.release();
            this.extractor = null;
        }
        this.extractorInput = null;
    }

    @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor
    public void seek(long j10, long j11) {
        ((y) Assertions.checkNotNull(this.extractor)).seek(j10, j11);
    }
}
