Search in sources :

Example 21 with Entry

use of com.google.android.exoplayer2.metadata.Metadata.Entry in project ExoPlayer by google.

the class VbriSeeker method create.

/**
 * Returns a {@link VbriSeeker} for seeking in the stream, if required information is present.
 * Returns {@code null} if not. On returning, {@code frame}'s position is not specified so the
 * caller should reset it.
 *
 * @param inputLength The length of the stream in bytes, or {@link C#LENGTH_UNSET} if unknown.
 * @param position The position of the start of this frame in the stream.
 * @param mpegAudioHeader The MPEG audio header associated with the frame.
 * @param frame The data in this audio frame, with its position set to immediately after the
 *     'VBRI' tag.
 * @return A {@link VbriSeeker} for seeking in the stream, or {@code null} if the required
 *     information is not present.
 */
@Nullable
public static VbriSeeker create(long inputLength, long position, MpegAudioUtil.Header mpegAudioHeader, ParsableByteArray frame) {
    frame.skipBytes(10);
    int numFrames = frame.readInt();
    if (numFrames <= 0) {
        return null;
    }
    int sampleRate = mpegAudioHeader.sampleRate;
    long durationUs = Util.scaleLargeTimestamp(numFrames, C.MICROS_PER_SECOND * (sampleRate >= 32000 ? 1152 : 576), sampleRate);
    int entryCount = frame.readUnsignedShort();
    int scale = frame.readUnsignedShort();
    int entrySize = frame.readUnsignedShort();
    frame.skipBytes(2);
    long minPosition = position + mpegAudioHeader.frameSize;
    // Read table of contents entries.
    long[] timesUs = new long[entryCount];
    long[] positions = new long[entryCount];
    for (int index = 0; index < entryCount; index++) {
        timesUs[index] = (index * durationUs) / entryCount;
        // Ensure positions do not fall within the frame containing the VBRI header. This constraint
        // will normally only apply to the first entry in the table.
        positions[index] = max(position, minPosition);
        int segmentSize;
        switch(entrySize) {
            case 1:
                segmentSize = frame.readUnsignedByte();
                break;
            case 2:
                segmentSize = frame.readUnsignedShort();
                break;
            case 3:
                segmentSize = frame.readUnsignedInt24();
                break;
            case 4:
                segmentSize = frame.readUnsignedIntToInt();
                break;
            default:
                return null;
        }
        position += segmentSize * scale;
    }
    if (inputLength != C.LENGTH_UNSET && inputLength != position) {
        Log.w(TAG, "VBRI data size mismatch: " + inputLength + ", " + position);
    }
    return new VbriSeeker(timesUs, positions, durationUs, /* dataEndPosition= */
    position);
}
Also used : SeekPoint(com.google.android.exoplayer2.extractor.SeekPoint) Nullable(androidx.annotation.Nullable)

Example 22 with Entry

use of com.google.android.exoplayer2.metadata.Metadata.Entry in project ExoPlayer by google.

the class AtomParsers method parseIlst.

@Nullable
private static Metadata parseIlst(ParsableByteArray ilst, int limit) {
    ilst.skipBytes(Atom.HEADER_SIZE);
    ArrayList<Metadata.Entry> entries = new ArrayList<>();
    while (ilst.getPosition() < limit) {
        @Nullable Metadata.Entry entry = MetadataUtil.parseIlstElement(ilst);
        if (entry != null) {
            entries.add(entry);
        }
    }
    return entries.isEmpty() ? null : new Metadata(entries);
}
Also used : SmtaMetadataEntry(com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry) ArrayList(java.util.ArrayList) Metadata(com.google.android.exoplayer2.metadata.Metadata) Nullable(androidx.annotation.Nullable) Nullable(androidx.annotation.Nullable)

Aggregations

Metadata (com.google.android.exoplayer2.metadata.Metadata)12 Nullable (androidx.annotation.Nullable)9 ArrayList (java.util.ArrayList)8 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)4 Test (org.junit.Test)4 SmtaMetadataEntry (com.google.android.exoplayer2.metadata.mp4.SmtaMetadataEntry)3 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)3 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)3 SpannableStringBuilder (android.text.SpannableStringBuilder)2 Format (com.google.android.exoplayer2.Format)2 RendererConfiguration (com.google.android.exoplayer2.RendererConfiguration)2 Id3Frame (com.google.android.exoplayer2.metadata.id3.Id3Frame)2 SlowMotionData (com.google.android.exoplayer2.metadata.mp4.SlowMotionData)2 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)2 Cue (com.google.android.exoplayer2.text.Cue)2 TreeMap (java.util.TreeMap)2 Bitmap (android.graphics.Bitmap)1 Uri (android.net.Uri)1 Pair (android.util.Pair)1 ExoPlayerVideoDisplayComponent (com.brightcove.player.display.ExoPlayerVideoDisplayComponent)1