Search in sources :

Example 11 with ReadDataResult

use of com.google.android.exoplayer2.source.SampleStream.ReadDataResult in project ExoPlayer by google.

the class MetadataRenderer method readMetadata.

private void readMetadata() {
    if (!inputStreamEnded && pendingMetadata == null) {
        buffer.clear();
        FormatHolder formatHolder = getFormatHolder();
        @ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
        0);
        if (result == C.RESULT_BUFFER_READ) {
            if (buffer.isEndOfStream()) {
                inputStreamEnded = true;
            } else {
                buffer.subsampleOffsetUs = subsampleOffsetUs;
                buffer.flip();
                @Nullable Metadata metadata = castNonNull(decoder).decode(buffer);
                if (metadata != null) {
                    List<Metadata.Entry> entries = new ArrayList<>(metadata.length());
                    decodeWrappedMetadata(metadata, entries);
                    if (!entries.isEmpty()) {
                        Metadata expandedMetadata = new Metadata(entries);
                        pendingMetadata = expandedMetadata;
                        pendingMetadataTimestampUs = buffer.timeUs;
                    }
                }
            }
        } else if (result == C.RESULT_FORMAT_READ) {
            subsampleOffsetUs = Assertions.checkNotNull(formatHolder.format).subsampleOffsetUs;
        }
    }
}
Also used : ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder) ArrayList(java.util.ArrayList) Nullable(androidx.annotation.Nullable)

Aggregations

ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)11 FormatHolder (com.google.android.exoplayer2.FormatHolder)9 Nullable (androidx.annotation.Nullable)4 Format (com.google.android.exoplayer2.Format)4 DecoderException (com.google.android.exoplayer2.decoder.DecoderException)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)1 ArrayList (java.util.ArrayList)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1