Consolidate TransformationResult.transformationException test usage.

PiperOrigin-RevId: 504257627
This commit is contained in:
samrobinson 2023-01-24 14:28:16 +00:00 committed by christosts
parent 1f9a33279e
commit a010ebf7b6
2 changed files with 9 additions and 37 deletions

View file

@ -37,7 +37,6 @@ public class TransformationTestResult {
private long elapsedTimeMs;
private double ssim;
@Nullable private FallbackDetails fallbackDetails;
@Nullable private Exception testException;
@Nullable private Exception analysisException;
/** Creates a new {@link Builder}. */
@ -105,20 +104,6 @@ public class TransformationTestResult {
return this;
}
/**
* Sets an {@link Exception} that occurred during the test.
*
* <p>{@code null} represents an unset or unknown value.
*
* @param testException The {@link Exception} thrown during the test.
* @return This {@link Builder}.
*/
@CanIgnoreReturnValue
public Builder setTestException(@Nullable Exception testException) {
this.testException = testException;
return this;
}
/**
* Sets an {@link Exception} that occurred during post-transformation analysis.
*
@ -136,13 +121,7 @@ public class TransformationTestResult {
/** Builds the {@link TransformationTestResult} instance. */
public TransformationTestResult build() {
return new TransformationTestResult(
transformationResult,
filePath,
elapsedTimeMs,
ssim,
fallbackDetails,
testException,
analysisException);
transformationResult, filePath, elapsedTimeMs, ssim, fallbackDetails, analysisException);
}
}
@ -167,8 +146,6 @@ public class TransformationTestResult {
* {@code null} if no fallback occurred.
*/
@Nullable public final FallbackDetails fallbackDetails;
/** The {@link Exception} thrown during the test, or {@code null} if nothing was thrown. */
@Nullable public final Exception testException;
/**
* The {@link Exception} thrown during post-transformation analysis, or {@code null} if nothing
* was thrown.
@ -187,7 +164,9 @@ public class TransformationTestResult {
.putOpt("colorInfo", transformationResult.colorInfo)
.putOpt("videoDecoderName", transformationResult.videoDecoderName)
.putOpt("videoEncoderName", transformationResult.videoEncoderName)
.putOpt("testException", exceptionAsJsonObject(testException))
.putOpt(
"testException",
exceptionAsJsonObject(transformationResult.transformationException))
.putOpt("analysisException", exceptionAsJsonObject(analysisException));
if (transformationResult.averageAudioBitrate != C.RATE_UNSET_INT) {
@ -238,14 +217,12 @@ public class TransformationTestResult {
long elapsedTimeMs,
double ssim,
@Nullable FallbackDetails fallbackDetails,
@Nullable Exception testException,
@Nullable Exception analysisException) {
this.transformationResult = transformationResult;
this.filePath = filePath;
this.elapsedTimeMs = elapsedTimeMs;
this.ssim = ssim;
this.fallbackDetails = fallbackDetails;
this.testException = testException;
this.analysisException = analysisException;
this.throughputFps =
elapsedTimeMs != C.TIME_UNSET && transformationResult.videoFrameCount > 0

View file

@ -204,8 +204,8 @@ public class TransformerAndroidTestRunner {
try {
TransformationTestResult transformationTestResult = runInternal(testId, editedMediaItem);
resultJson.put("transformationResult", transformationTestResult.asJsonObject());
if (transformationTestResult.testException != null) {
throw transformationTestResult.testException;
if (transformationTestResult.transformationResult.transformationException != null) {
throw transformationTestResult.transformationResult.transformationException;
}
if (!suppressAnalysisExceptions && transformationTestResult.analysisException != null) {
throw transformationTestResult.analysisException;
@ -257,8 +257,6 @@ public class TransformerAndroidTestRunner {
AtomicReference<@NullableType FallbackDetails> fallbackDetailsReference =
new AtomicReference<>();
AtomicReference<@NullableType TransformationException> transformationExceptionReference =
new AtomicReference<>();
AtomicReference<@NullableType Exception> unexpectedExceptionReference = new AtomicReference<>();
AtomicReference<@NullableType TransformationResult> transformationResultReference =
new AtomicReference<>();
@ -282,7 +280,6 @@ public class TransformerAndroidTestRunner {
MediaItem inputMediaItem,
TransformationResult result,
TransformationException exception) {
transformationExceptionReference.set(exception);
transformationResultReference.set(result);
countDownLatch.countDown();
}
@ -337,14 +334,12 @@ public class TransformerAndroidTestRunner {
long elapsedTimeMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs;
@Nullable FallbackDetails fallbackDetails = fallbackDetailsReference.get();
@Nullable
TransformationException transformationException = transformationExceptionReference.get();
TransformationResult transformationResult = checkNotNull(transformationResultReference.get());
if (transformationException != null) {
return new TransformationTestResult.Builder(checkNotNull(transformationResultReference.get()))
if (transformationResult.transformationException != null) {
return new TransformationTestResult.Builder(transformationResult)
.setElapsedTimeMs(elapsedTimeMs)
.setFallbackDetails(fallbackDetails)
.setTestException(transformationException)
.build();
}