Make DecoderCountersUtil error message clearer

By including the full counters in the failure message we have a clearer
insight into the cause of the failure.

PiperOrigin-RevId: 415982732
This commit is contained in:
ibaker 2021-12-13 09:45:15 +00:00 committed by Ian Baker
parent e01ef47db9
commit 7fca1a0876
2 changed files with 51 additions and 40 deletions

View File

@ -17,6 +17,8 @@ package com.google.android.exoplayer2.decoder;
import static java.lang.Math.max; import static java.lang.Math.max;
import com.google.android.exoplayer2.util.Util;
/** /**
* Maintains decoder event counts, for debugging purposes only. * Maintains decoder event counts, for debugging purposes only.
* *
@ -154,4 +156,34 @@ public final class DecoderCounters {
totalVideoFrameProcessingOffsetUs += totalProcessingOffsetUs; totalVideoFrameProcessingOffsetUs += totalProcessingOffsetUs;
videoFrameProcessingOffsetCount += count; videoFrameProcessingOffsetCount += count;
} }
@Override
public String toString() {
return Util.formatInvariant(
"DecoderCounters {\n "
+ "decoderInits=%s,\n "
+ "decoderReleases=%s\n "
+ "queuedInputBuffers=%s\n "
+ "skippedInputBuffers=%s\n "
+ "renderedOutputBuffers=%s\n "
+ "skippedOutputBuffers=%s\n "
+ "droppedBuffers=%s\n "
+ "droppedInputBuffers=%s\n "
+ "maxConsecutiveDroppedBuffers=%s\n "
+ "droppedToKeyframeEvents=%s\n "
+ "totalVideoFrameProcessingOffsetUs=%s\n "
+ "videoFrameProcessingOffsetCount=%s\n}",
decoderInitCount,
decoderReleaseCount,
queuedInputBufferCount,
skippedInputBufferCount,
renderedOutputBufferCount,
skippedOutputBufferCount,
droppedBufferCount,
droppedInputBufferCount,
maxConsecutiveDroppedBufferCount,
droppedToKeyframeCount,
totalVideoFrameProcessingOffsetUs,
videoFrameProcessingOffsetCount);
}
} }

View File

@ -43,7 +43,7 @@ public final class DecoderCountersUtil {
counters.ensureUpdated(); counters.ensureUpdated();
int actual = counters.skippedOutputBufferCount; int actual = counters.skippedOutputBufferCount;
assertWithMessage( assertWithMessage(
"Codec(" + name + ") skipped " + actual + " buffers. Expected " + expected + ".") "Codec(%s) skipped an unexpected number of buffers. Counters:\n%s", name, counters)
.that(actual) .that(actual)
.isEqualTo(expected); .isEqualTo(expected);
} }
@ -66,32 +66,19 @@ public final class DecoderCountersUtil {
public static void assertTotalBufferCount( public static void assertTotalBufferCount(
String name, DecoderCounters counters, int minCount, int maxCount) { String name, DecoderCounters counters, int minCount, int maxCount) {
int actual = getTotalBufferCount(counters); int actual = getTotalBufferCount(counters);
assertWithMessage( assertWithMessage("Codec(%s) output too few buffers. Counters:\n%s", name, counters)
"Codec(" .that(actual)
+ name .isAtLeast(minCount);
+ ") output " assertWithMessage("Codec(%s) output too many buffers. Counters:\n%s", name, counters)
+ actual .that(actual)
+ " buffers. Expected in range [" .isAtMost(maxCount);
+ minCount
+ ", "
+ maxCount
+ "].")
.that(minCount <= actual && actual <= maxCount)
.isTrue();
} }
public static void assertDroppedBufferLimit(String name, DecoderCounters counters, int limit) { public static void assertDroppedBufferLimit(String name, DecoderCounters counters, int limit) {
counters.ensureUpdated(); counters.ensureUpdated();
int actual = counters.droppedBufferCount; int actual = counters.droppedBufferCount;
assertWithMessage( assertWithMessage(
"Codec(" "Codec(%s) was late decoding too many buffers. Counters:\n%s: ", name, counters)
+ name
+ ") was late decoding: "
+ actual
+ " buffers. "
+ "Limit: "
+ limit
+ ".")
.that(actual) .that(actual)
.isAtMost(limit); .isAtMost(limit);
} }
@ -101,14 +88,8 @@ public final class DecoderCountersUtil {
counters.ensureUpdated(); counters.ensureUpdated();
int actual = counters.maxConsecutiveDroppedBufferCount; int actual = counters.maxConsecutiveDroppedBufferCount;
assertWithMessage( assertWithMessage(
"Codec(" "Codec(%s) was late decoding too many buffers consecutively. Counters:\n%s",
+ name name, counters)
+ ") was late decoding: "
+ actual
+ " buffers consecutively. "
+ "Limit: "
+ limit
+ ".")
.that(actual) .that(actual)
.isAtMost(limit); .isAtMost(limit);
} }
@ -117,16 +98,14 @@ public final class DecoderCountersUtil {
String name, DecoderCounters counters, int minCount, int maxCount) { String name, DecoderCounters counters, int minCount, int maxCount) {
int actual = counters.videoFrameProcessingOffsetCount; int actual = counters.videoFrameProcessingOffsetCount;
assertWithMessage( assertWithMessage(
"Codec(" "Codec(%s) videoFrameProcessingOffsetSampleCount too low. Counters:\n%s",
+ name name, counters)
+ ") videoFrameProcessingOffsetSampleCount " .that(actual)
+ actual .isAtLeast(minCount);
+ ". Expected in range [" assertWithMessage(
+ minCount "Codec(%s) videoFrameProcessingOffsetSampleCount too high. Counters:\n%s",
+ ", " name, counters)
+ maxCount .that(actual)
+ "].") .isAtMost(maxCount);
.that(minCount <= actual && actual <= maxCount)
.isTrue();
} }
} }