package androidx.media3.exoplayer.hls;

import androidx.annotation.VisibleForTesting;
import androidx.media3.common.Format;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.TimestampAdjuster;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.extractor.b0;
import androidx.media3.extractor.r0;
import androidx.media3.extractor.y;
import androidx.media3.extractor.z;
import java.io.IOException;
import l2.q;
import n2.n;
import x2.k0;

/* JADX INFO: loaded from: classes.dex */
@UnstableApi
public final class BundledHlsMediaChunkExtractor implements HlsMediaChunkExtractor {
    private static final r0 POSITION_HOLDER = new r0();

    @VisibleForTesting
    final y extractor;
    private final Format multivariantPlaylistFormat;
    private final boolean parseSubtitlesDuringExtraction;
    private final n subtitleParserFactory;
    private final TimestampAdjuster timestampAdjuster;

    public BundledHlsMediaChunkExtractor(y yVar, Format format, TimestampAdjuster timestampAdjuster) {
        this(yVar, format, timestampAdjuster, n.f30781a, false);
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public void init(b0 b0Var) {
        this.extractor.init(b0Var);
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public boolean isPackedAudioExtractor() {
        y underlyingImplementation = this.extractor.getUnderlyingImplementation();
        return (underlyingImplementation instanceof x2.e) || (underlyingImplementation instanceof x2.a) || (underlyingImplementation instanceof x2.c) || (underlyingImplementation instanceof k2.d);
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public boolean isReusable() {
        y underlyingImplementation = this.extractor.getUnderlyingImplementation();
        return (underlyingImplementation instanceof k0) || (underlyingImplementation instanceof q);
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public void onTruncatedSegmentParsed() {
        this.extractor.seek(0L, 0L);
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public boolean read(z zVar) throws IOException {
        return this.extractor.read(zVar, POSITION_HOLDER) == 0;
    }

    @Override // androidx.media3.exoplayer.hls.HlsMediaChunkExtractor
    public HlsMediaChunkExtractor recreate() {
        y dVar;
        Assertions.checkState(!isReusable());
        Assertions.checkState(this.extractor.getUnderlyingImplementation() == this.extractor, "Can't recreate wrapped extractors. Outer type: " + this.extractor.getClass());
        y yVar = this.extractor;
        if (yVar instanceof WebvttExtractor) {
            dVar = new WebvttExtractor(this.multivariantPlaylistFormat.language, this.timestampAdjuster, this.subtitleParserFactory, this.parseSubtitlesDuringExtraction);
        } else if (yVar instanceof x2.e) {
            dVar = new x2.e();
        } else if (yVar instanceof x2.a) {
            dVar = new x2.a();
        } else if (yVar instanceof x2.c) {
            dVar = new x2.c();
        } else {
            if (!(yVar instanceof k2.d)) {
                throw new IllegalStateException("Unexpected extractor type for recreation: ".concat(this.extractor.getClass().getSimpleName()));
            }
            dVar = new k2.d();
        }
        return new BundledHlsMediaChunkExtractor(dVar, this.multivariantPlaylistFormat, this.timestampAdjuster, this.subtitleParserFactory, this.parseSubtitlesDuringExtraction);
    }

    public BundledHlsMediaChunkExtractor(y yVar, Format format, TimestampAdjuster timestampAdjuster, n nVar, boolean z10) {
        this.extractor = yVar;
        this.multivariantPlaylistFormat = format;
        this.timestampAdjuster = timestampAdjuster;
        this.subtitleParserFactory = nVar;
        this.parseSubtitlesDuringExtraction = z10;
    }
}
