Search in sources :

Example 1 with ExtractorOutput

use of androidx.media3.extractor.ExtractorOutput in project ExoPlayer by google.

the class Mp4Extractor method processMoovAtom.

/**
 * Updates the stored track metadata to reflect the contents of the specified moov atom.
 */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
    int firstVideoTrackIndex = C.INDEX_UNSET;
    long durationUs = C.TIME_UNSET;
    List<Mp4Track> tracks = new ArrayList<>();
    // Process metadata.
    @Nullable Metadata udtaMetaMetadata = null;
    @Nullable Metadata smtaMetadata = null;
    boolean isQuickTime = fileType == FILE_TYPE_QUICKTIME;
    GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder();
    @Nullable Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
    if (udta != null) {
        Pair<@NullableType Metadata, @NullableType Metadata> udtaMetadata = AtomParsers.parseUdta(udta);
        udtaMetaMetadata = udtaMetadata.first;
        smtaMetadata = udtaMetadata.second;
        if (udtaMetaMetadata != null) {
            gaplessInfoHolder.setFromMetadata(udtaMetaMetadata);
        }
    }
    @Nullable Metadata mdtaMetadata = null;
    @Nullable Atom.ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta);
    if (meta != null) {
        mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta);
    }
    boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0;
    List<TrackSampleTable> trackSampleTables = parseTraks(moov, gaplessInfoHolder, /* duration= */
    C.TIME_UNSET, /* drmInitData= */
    null, ignoreEditLists, isQuickTime, /* modifyTrackFunction= */
    track -> track);
    ExtractorOutput extractorOutput = checkNotNull(this.extractorOutput);
    int trackCount = trackSampleTables.size();
    for (int i = 0; i < trackCount; i++) {
        TrackSampleTable trackSampleTable = trackSampleTables.get(i);
        if (trackSampleTable.sampleCount == 0) {
            continue;
        }
        Track track = trackSampleTable.track;
        long trackDurationUs = track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs;
        durationUs = max(durationUs, trackDurationUs);
        Mp4Track mp4Track = new Mp4Track(track, trackSampleTable, extractorOutput.track(i, track.type));
        int maxInputSize;
        if (MimeTypes.AUDIO_TRUEHD.equals(track.format.sampleMimeType)) {
            // TrueHD groups samples per chunks of TRUEHD_RECHUNK_SAMPLE_COUNT samples.
            maxInputSize = trackSampleTable.maximumSize * Ac3Util.TRUEHD_RECHUNK_SAMPLE_COUNT;
        } else {
            // Each sample has up to three bytes of overhead for the start code that replaces its
            // length. Allow ten source samples per output sample, like the platform extractor.
            maxInputSize = trackSampleTable.maximumSize + 3 * 10;
        }
        Format.Builder formatBuilder = track.format.buildUpon();
        formatBuilder.setMaxInputSize(maxInputSize);
        if (track.type == C.TRACK_TYPE_VIDEO && trackDurationUs > 0 && trackSampleTable.sampleCount > 1) {
            float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f);
            formatBuilder.setFrameRate(frameRate);
        }
        MetadataUtil.setFormatGaplessInfo(track.type, gaplessInfoHolder, formatBuilder);
        MetadataUtil.setFormatMetadata(track.type, udtaMetaMetadata, mdtaMetadata, formatBuilder, smtaMetadata, slowMotionMetadataEntries.isEmpty() ? null : new Metadata(slowMotionMetadataEntries));
        mp4Track.trackOutput.format(formatBuilder.build());
        if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
            firstVideoTrackIndex = tracks.size();
        }
        tracks.add(mp4Track);
    }
    this.firstVideoTrackIndex = firstVideoTrackIndex;
    this.durationUs = durationUs;
    this.tracks = tracks.toArray(new Mp4Track[0]);
    accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks);
    extractorOutput.endTracks();
    extractorOutput.seekMap(this);
}
Also used : ExtractorOutput(com.google.android.exoplayer2.extractor.ExtractorOutput) ArrayList(java.util.ArrayList) MotionPhotoMetadata(com.google.android.exoplayer2.metadata.mp4.MotionPhotoMetadata) Metadata(com.google.android.exoplayer2.metadata.Metadata) ContainerAtom(com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom) SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) ContainerAtom(com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom) Format(com.google.android.exoplayer2.Format) GaplessInfoHolder(com.google.android.exoplayer2.extractor.GaplessInfoHolder) Nullable(androidx.annotation.Nullable)

Example 2 with ExtractorOutput

use of androidx.media3.extractor.ExtractorOutput in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToZero.

@Test
public void seeking_seekTable_handlesSeekToZero() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 3 with ExtractorOutput

use of androidx.media3.extractor.ExtractorOutput in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekingForward.

@Test
public void seeking_seekTable_handlesSeekingForward() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 987_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_234_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 4 with ExtractorOutput

use of androidx.media3.extractor.ExtractorOutput in project media by androidx.

the class FlacExtractorSeekTest method seeking_binarySearch_handlesSeekingForward.

@Test
public void seeking_binarySearch_handlesSeekingForward() throws IOException {
    String fileName = TEST_FILE_BINARY_SEARCH;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 987_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_234_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekContainsTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 5 with ExtractorOutput

use of androidx.media3.extractor.ExtractorOutput in project media by androidx.

the class FlacExtractorSeekTest method seeking_seekTable_handlesSeekToEoF.

@Test
public void seeking_seekTable_handlesSeekToEoF() throws IOException {
    String fileName = TEST_FILE_SEEK_TABLE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekPrecedesTargetSeekTime(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(androidx.media3.test.utils.FakeTrackOutput) SeekMap(androidx.media3.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

SeekMap (androidx.media3.extractor.SeekMap)72 Test (org.junit.Test)66 Uri (android.net.Uri)59 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)57 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)31 Nullable (androidx.annotation.Nullable)8 TrackOutput (androidx.media3.extractor.TrackOutput)5 Format (androidx.media3.common.Format)4 Metadata (androidx.media3.common.Metadata)4 Before (org.junit.Before)4 ExtractorInput (androidx.media3.extractor.ExtractorInput)3 MotionPhotoMetadata (androidx.media3.extractor.metadata.mp4.MotionPhotoMetadata)3 TrackIdGenerator (androidx.media3.extractor.ts.TsPayloadReader.TrackIdGenerator)3 ExtractorOutput (com.google.android.exoplayer2.extractor.ExtractorOutput)3 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)3 ParsableByteArray (androidx.media3.common.util.ParsableByteArray)2 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)2 Extractor (androidx.media3.extractor.Extractor)2 ExtractorOutput (androidx.media3.extractor.ExtractorOutput)2 IndexSeekMap (androidx.media3.extractor.IndexSeekMap)2