Fix video timestamp 0 set to large value in some cases
PiperOrigin-RevId: 525064269
This commit is contained in:
parent
ffa969f97c
commit
23b1cab56c
@ -67,6 +67,7 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
private final EncoderWrapper encoderWrapper;
|
private final EncoderWrapper encoderWrapper;
|
||||||
private final DecoderInputBuffer encoderOutputBuffer;
|
private final DecoderInputBuffer encoderOutputBuffer;
|
||||||
|
|
||||||
|
private volatile boolean encoderExpectsTimestampZero;
|
||||||
/**
|
/**
|
||||||
* The timestamp of the last buffer processed before {@linkplain
|
* The timestamp of the last buffer processed before {@linkplain
|
||||||
* VideoFrameProcessor.Listener#onEnded() frame processing has ended}.
|
* VideoFrameProcessor.Listener#onEnded() frame processing has ended}.
|
||||||
@ -158,6 +159,9 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
@Override
|
@Override
|
||||||
public void onOutputFrameAvailable(long presentationTimeUs) {
|
public void onOutputFrameAvailable(long presentationTimeUs) {
|
||||||
// Frames are released automatically.
|
// Frames are released automatically.
|
||||||
|
if (presentationTimeUs == 0) {
|
||||||
|
encoderExpectsTimestampZero = true;
|
||||||
|
}
|
||||||
lastProcessedFramePresentationTimeUs = presentationTimeUs;
|
lastProcessedFramePresentationTimeUs = presentationTimeUs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,16 +258,16 @@ import org.checkerframework.dataflow.qual.Pure;
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
MediaCodec.BufferInfo bufferInfo = checkNotNull(encoderWrapper.getOutputBufferInfo());
|
MediaCodec.BufferInfo bufferInfo = checkNotNull(encoderWrapper.getOutputBufferInfo());
|
||||||
if (finalFramePresentationTimeUs != C.TIME_UNSET
|
if (bufferInfo.presentationTimeUs == 0) {
|
||||||
&& bufferInfo.size > 0
|
|
||||||
&& bufferInfo.presentationTimeUs == 0) {
|
|
||||||
// Internal ref b/235045165: Some encoder incorrectly set a zero presentation time on the
|
// Internal ref b/235045165: Some encoder incorrectly set a zero presentation time on the
|
||||||
// penultimate buffer (before EOS), and sets the actual timestamp on the EOS buffer. Use the
|
// penultimate buffer (before EOS), and sets the actual timestamp on the EOS buffer. Use the
|
||||||
// last processed frame presentation time instead.
|
// last processed frame presentation time instead.
|
||||||
// bufferInfo.presentationTimeUs should never be 0 because we apply streamOffsetUs to the
|
if (encoderExpectsTimestampZero) {
|
||||||
// buffer presentationTimeUs.
|
encoderExpectsTimestampZero = false;
|
||||||
|
} else if (finalFramePresentationTimeUs != C.TIME_UNSET && bufferInfo.size > 0) {
|
||||||
bufferInfo.presentationTimeUs = finalFramePresentationTimeUs;
|
bufferInfo.presentationTimeUs = finalFramePresentationTimeUs;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
encoderOutputBuffer.timeUs = bufferInfo.presentationTimeUs;
|
encoderOutputBuffer.timeUs = bufferInfo.presentationTimeUs;
|
||||||
encoderOutputBuffer.setFlags(bufferInfo.flags);
|
encoderOutputBuffer.setFlags(bufferInfo.flags);
|
||||||
return encoderOutputBuffer;
|
return encoderOutputBuffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user