Mark dropped buffers while joining as skipped.

These buffers are intentionally dropped to catch up with the playing audio.
Mark them as skipped accordingly.

PiperOrigin-RevId: 268703410
This commit is contained in:
tonihei 2019-09-12 17:39:59 +01:00 committed by Oliver Woodman
parent dc12982bd1
commit 65748fa8ee

View File

@ -836,11 +836,17 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
bufferPresentationTimeUs, unadjustedFrameReleaseTimeNs);
earlyUs = (adjustedReleaseTimeNs - systemTimeNs) / 1000;
boolean treatDroppedBuffersAsSkipped = joiningDeadlineMs != C.TIME_UNSET;
if (shouldDropBuffersToKeyframe(earlyUs, elapsedRealtimeUs, isLastBuffer)
&& maybeDropBuffersToKeyframe(codec, bufferIndex, presentationTimeUs, positionUs)) {
&& maybeDropBuffersToKeyframe(
codec, bufferIndex, presentationTimeUs, positionUs, treatDroppedBuffersAsSkipped)) {
return false;
} else if (shouldDropOutputBuffer(earlyUs, elapsedRealtimeUs, isLastBuffer)) {
if (treatDroppedBuffersAsSkipped) {
skipOutputBuffer(codec, bufferIndex, presentationTimeUs);
} else {
dropOutputBuffer(codec, bufferIndex, presentationTimeUs);
}
return true;
}
@ -1033,11 +1039,18 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
* @param index The index of the output buffer to drop.
* @param presentationTimeUs The presentation time of the output buffer, in microseconds.
* @param positionUs The current playback position, in microseconds.
* @param treatDroppedBuffersAsSkipped Whether dropped buffers should be treated as intentionally
* skipped.
* @return Whether any buffers were dropped.
* @throws ExoPlaybackException If an error occurs flushing the codec.
*/
protected boolean maybeDropBuffersToKeyframe(MediaCodec codec, int index, long presentationTimeUs,
long positionUs) throws ExoPlaybackException {
protected boolean maybeDropBuffersToKeyframe(
MediaCodec codec,
int index,
long presentationTimeUs,
long positionUs,
boolean treatDroppedBuffersAsSkipped)
throws ExoPlaybackException {
int droppedSourceBufferCount = skipSource(positionUs);
if (droppedSourceBufferCount == 0) {
return false;
@ -1045,7 +1058,12 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
decoderCounters.droppedToKeyframeCount++;
// We dropped some buffers to catch up, so update the decoder counters and flush the codec,
// which releases all pending buffers buffers including the current output buffer.
updateDroppedBufferCounters(buffersInCodecCount + droppedSourceBufferCount);
int totalDroppedBufferCount = buffersInCodecCount + droppedSourceBufferCount;
if (treatDroppedBuffersAsSkipped) {
decoderCounters.skippedOutputBufferCount += totalDroppedBufferCount;
} else {
updateDroppedBufferCounters(totalDroppedBufferCount);
}
flushOrReinitializeCodec();
return true;
}