package androidx.media3.exoplayer.source; import android.media.MediaParser; import android.net.Uri; import android.util.Pair; import androidx.media3.common.DataReader; import androidx.media3.common.util.Util; import androidx.media3.exoplayer.analytics.PlayerId; import androidx.media3.exoplayer.source.ProgressiveMediaExtractor; import androidx.media3.exoplayer.source.mediaparser.InputReaderAdapterV30; import androidx.media3.exoplayer.source.mediaparser.MediaParserUtil; import androidx.media3.exoplayer.source.mediaparser.OutputConsumerAdapterV30; import androidx.media3.extractor.ExtractorOutput; import androidx.media3.extractor.PositionHolder; import java.io.IOException; import java.util.List; import java.util.Map; /* loaded from: classes2.dex */ public final class MediaParserExtractorAdapter implements ProgressiveMediaExtractor { public static final ProgressiveMediaExtractor.Factory FACTORY = new ProgressiveMediaExtractor.Factory() { // from class: androidx.media3.exoplayer.source.MediaParserExtractorAdapter$$ExternalSyntheticLambda0 @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor.Factory public final ProgressiveMediaExtractor createProgressiveMediaExtractor(PlayerId playerId) { return new MediaParserExtractorAdapter(playerId); } }; private final InputReaderAdapterV30 inputReaderAdapter; private final MediaParser mediaParser; private final OutputConsumerAdapterV30 outputConsumerAdapter; private String parserName; public MediaParserExtractorAdapter(PlayerId playerId) { OutputConsumerAdapterV30 outputConsumerAdapterV30 = new OutputConsumerAdapterV30(); this.outputConsumerAdapter = outputConsumerAdapterV30; this.inputReaderAdapter = new InputReaderAdapterV30(); MediaParser create = MediaParser.create(outputConsumerAdapterV30, new String[0]); this.mediaParser = create; create.setParameter("android.media.mediaparser.eagerlyExposeTrackType", true); create.setParameter("android.media.mediaparser.inBandCryptoInfo", true); create.setParameter("android.media.mediaparser.includeSupplementalData", true); this.parserName = "android.media.mediaparser.UNKNOWN"; if (Util.SDK_INT >= 31) { MediaParserUtil.setLogSessionIdOnMediaParser(create, playerId); } } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public void init(DataReader dataReader, Uri uri, Map> map, long j, long j2, ExtractorOutput extractorOutput) throws IOException { this.outputConsumerAdapter.setExtractorOutput(extractorOutput); this.inputReaderAdapter.setDataReader(dataReader, j2); this.inputReaderAdapter.setCurrentPosition(j); String parserName = this.mediaParser.getParserName(); if ("android.media.mediaparser.UNKNOWN".equals(parserName)) { this.mediaParser.advance(this.inputReaderAdapter); String parserName2 = this.mediaParser.getParserName(); this.parserName = parserName2; this.outputConsumerAdapter.setSelectedParserName(parserName2); return; } if (parserName.equals(this.parserName)) { return; } String parserName3 = this.mediaParser.getParserName(); this.parserName = parserName3; this.outputConsumerAdapter.setSelectedParserName(parserName3); } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public void release() { this.mediaParser.release(); } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public void disableSeekingOnMp3Streams() { if ("android.media.mediaparser.Mp3Parser".equals(this.parserName)) { this.outputConsumerAdapter.disableSeeking(); } } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public long getCurrentInputPosition() { return this.inputReaderAdapter.getPosition(); } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public void seek(long j, long j2) { this.inputReaderAdapter.setCurrentPosition(j); Pair seekPoints = this.outputConsumerAdapter.getSeekPoints(j2); this.mediaParser.seek((MediaParser.SeekPoint) (((MediaParser.SeekPoint) seekPoints.second).position == j ? seekPoints.second : seekPoints.first)); } @Override // androidx.media3.exoplayer.source.ProgressiveMediaExtractor public int read(PositionHolder positionHolder) throws IOException { boolean advance = this.mediaParser.advance(this.inputReaderAdapter); positionHolder.position = this.inputReaderAdapter.getAndResetSeekPosition(); if (advance) { return positionHolder.position != -1 ? 1 : 0; } return -1; } }