use of androidx.media3.exoplayer.source.SampleStream.ReadDataResult in project media by androidx.
the class MediaCodecRenderer method bypassRead.
private void bypassRead() throws ExoPlaybackException {
checkState(!inputStreamEnded);
FormatHolder formatHolder = getFormatHolder();
bypassSampleBuffer.clear();
while (true) {
bypassSampleBuffer.clear();
@ReadDataResult int result = readSource(formatHolder, bypassSampleBuffer, /* readFlags= */
0);
switch(result) {
case C.RESULT_FORMAT_READ:
onInputFormatChanged(formatHolder);
return;
case C.RESULT_NOTHING_READ:
return;
case C.RESULT_BUFFER_READ:
if (bypassSampleBuffer.isEndOfStream()) {
inputStreamEnded = true;
return;
}
if (waitingForFirstSampleInFormat) {
// This is the first buffer in a new format, the output format must be updated.
outputFormat = checkNotNull(inputFormat);
onOutputFormatChanged(outputFormat, /* mediaFormat= */
null);
waitingForFirstSampleInFormat = false;
}
// Try to append the buffer to the batch buffer.
bypassSampleBuffer.flip();
if (!bypassBatchBuffer.append(bypassSampleBuffer)) {
bypassSampleBufferPending = true;
return;
}
break;
default:
throw new IllegalStateException();
}
}
}
use of androidx.media3.exoplayer.source.SampleStream.ReadDataResult in project media by androidx.
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;
}
}
}
use of androidx.media3.exoplayer.source.SampleStream.ReadDataResult in project media by androidx.
the class DecoderVideoRenderer method render.
// BaseRenderer implementation.
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (outputStreamEnded) {
return;
}
if (inputFormat == null) {
// We don't have a format yet, so try and read one.
FormatHolder formatHolder = getFormatHolder();
flagsOnlyBuffer.clear();
@ReadDataResult int result = readSource(formatHolder, flagsOnlyBuffer, FLAG_REQUIRE_FORMAT);
if (result == C.RESULT_FORMAT_READ) {
onInputFormatChanged(formatHolder);
} else if (result == C.RESULT_BUFFER_READ) {
// End of stream read having not read a format.
Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
inputStreamEnded = true;
outputStreamEnded = true;
return;
} else {
// We still don't have a format and can't make progress without one.
return;
}
}
// If we don't have a decoder yet, we need to instantiate one.
maybeInitDecoder();
if (decoder != null) {
try {
// Rendering loop.
TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {
}
while (feedInputBuffer()) {
}
TraceUtil.endSection();
} catch (DecoderException e) {
Log.e(TAG, "Video codec error", e);
eventDispatcher.videoCodecError(e);
throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODING_FAILED);
}
decoderCounters.ensureUpdated();
}
}
use of androidx.media3.exoplayer.source.SampleStream.ReadDataResult in project media by androidx.
the class CameraMotionRenderer method render.
@Override
public void render(long positionUs, long elapsedRealtimeUs) {
// Keep reading available samples as long as the sample time is not too far into the future.
while (!hasReadStreamToEnd() && lastTimestampUs < positionUs + SAMPLE_WINDOW_DURATION_US) {
buffer.clear();
FormatHolder formatHolder = getFormatHolder();
@ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
0);
if (result != C.RESULT_BUFFER_READ || buffer.isEndOfStream()) {
return;
}
lastTimestampUs = buffer.timeUs;
if (listener == null || buffer.isDecodeOnly()) {
continue;
}
buffer.flip();
@Nullable float[] rotation = parseMetadata(Util.castNonNull(buffer.data));
if (rotation == null) {
continue;
}
Util.castNonNull(listener).onCameraMotion(lastTimestampUs - offsetUs, rotation);
}
}
use of androidx.media3.exoplayer.source.SampleStream.ReadDataResult in project media by androidx.
the class FakeRenderer method render.
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (isEnded) {
return;
}
playbackPositionUs = positionUs;
while (true) {
if (!hasPendingBuffer) {
FormatHolder formatHolder = getFormatHolder();
buffer.clear();
@ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
0);
if (result == C.RESULT_FORMAT_READ) {
DrmSession.replaceSession(currentDrmSession, formatHolder.drmSession);
currentDrmSession = formatHolder.drmSession;
Format format = Assertions.checkNotNull(formatHolder.format);
if (MimeTypes.getTrackType(format.sampleMimeType) != getTrackType()) {
throw ExoPlaybackException.createForRenderer(new IllegalStateException(Util.formatInvariant("Format track type (%s) doesn't match renderer track type (%s).", MimeTypes.getTrackType(format.sampleMimeType), getTrackType())), getName(), getIndex(), format, C.FORMAT_UNSUPPORTED_TYPE, /* isRecoverable= */
false, PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
}
formatsRead.add(format);
onFormatChanged(format);
} else if (result == C.RESULT_BUFFER_READ) {
if (buffer.isEndOfStream()) {
isEnded = true;
return;
}
hasPendingBuffer = true;
} else {
Assertions.checkState(result == C.RESULT_NOTHING_READ);
return;
}
}
if (hasPendingBuffer) {
if (!shouldProcessBuffer(buffer.timeUs, positionUs)) {
return;
}
lastSamplePositionUs = buffer.timeUs;
sampleBufferReadCount++;
hasPendingBuffer = false;
}
}
}
Aggregations