com.google.android.exoplayer.extractor.GaplessInfo

Here are the examples of the java api class com.google.android.exoplayer.extractor.GaplessInfo taken from open source projects.

1. Mp4Extractor#processMoovAtom()

Project: ExoPlayer
File: Mp4Extractor.java
/**
   * Updates the stored track metadata to reflect the contents of the specified moov atom.
   */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
    List<Mp4Track> tracks = new ArrayList<>();
    long earliestSampleOffset = Long.MAX_VALUE;
    GaplessInfo gaplessInfo = null;
    Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
    if (udta != null) {
        gaplessInfo = AtomParsers.parseUdta(udta, isQuickTime);
    }
    for (int i = 0; i < moov.containerChildren.size(); i++) {
        Atom.ContainerAtom atom = moov.containerChildren.get(i);
        if (atom.type != Atom.TYPE_trak) {
            continue;
        }
        Track track = AtomParsers.parseTrak(atom, moov.getLeafAtomOfType(Atom.TYPE_mvhd), -1, isQuickTime);
        if (track == null) {
            continue;
        }
        Atom.ContainerAtom stblAtom = atom.getContainerAtomOfType(Atom.TYPE_mdia).getContainerAtomOfType(Atom.TYPE_minf).getContainerAtomOfType(Atom.TYPE_stbl);
        TrackSampleTable trackSampleTable = AtomParsers.parseStbl(track, stblAtom);
        if (trackSampleTable.sampleCount == 0) {
            continue;
        }
        Mp4Track mp4Track = new Mp4Track(track, trackSampleTable, extractorOutput.track(i));
        // 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.
        int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
        MediaFormat mediaFormat = track.mediaFormat.copyWithMaxInputSize(maxInputSize);
        if (gaplessInfo != null) {
            mediaFormat = mediaFormat.copyWithGaplessInfo(gaplessInfo.encoderDelay, gaplessInfo.encoderPadding);
        }
        mp4Track.trackOutput.format(mediaFormat);
        tracks.add(mp4Track);
        long firstSampleOffset = trackSampleTable.offsets[0];
        if (firstSampleOffset < earliestSampleOffset) {
            earliestSampleOffset = firstSampleOffset;
        }
    }
    this.tracks = tracks.toArray(new Mp4Track[0]);
    extractorOutput.endTracks();
    extractorOutput.seekMap(this);
}

2. Id3Util#parseId3()

Project: ExoPlayer
File: Id3Util.java
/**
   * Peeks data from the input and parses ID3 metadata.
   *
   * @param input The {@link ExtractorInput} from which data should be peeked.
   * @return The gapless playback information, if present and non-zero. {@code null} otherwise.
   * @throws IOException If an error occurred peeking from the input.
   * @throws InterruptedException If the thread was interrupted.
   */
public static GaplessInfo parseId3(ExtractorInput input) throws IOException, InterruptedException {
    ParsableByteArray scratch = new ParsableByteArray(10);
    int peekedId3Bytes = 0;
    GaplessInfo metadata = null;
    while (true) {
        input.peekFully(scratch.data, 0, 10);
        scratch.setPosition(0);
        if (scratch.readUnsignedInt24() != ID3_TAG) {
            break;
        }
        int majorVersion = scratch.readUnsignedByte();
        int minorVersion = scratch.readUnsignedByte();
        int flags = scratch.readUnsignedByte();
        int length = scratch.readSynchSafeInt();
        if (metadata == null && canParseMetadata(majorVersion, minorVersion, flags, length)) {
            byte[] frame = new byte[length];
            input.peekFully(frame, 0, length);
            metadata = parseGaplessInfo(new ParsableByteArray(frame), majorVersion, flags);
        } else {
            input.advancePeekPosition(length);
        }
        peekedId3Bytes += 10 + length;
    }
    input.resetPeekPosition();
    input.advancePeekPosition(peekedId3Bytes);
    return metadata;
}