Clarify SSIM request method name

`requestCalculateSsim` more clearly represents the intention of the caller.

Also rephrase the javadoc to simplify it and make it more precise.

PiperOrigin-RevId: 465575578
This commit is contained in:
andrewlewis 2022-08-05 16:02:07 +00:00 committed by tonihei
parent c95bfe325d
commit 2eb59fa1af
5 changed files with 25 additions and 26 deletions

View File

@ -52,7 +52,7 @@ public class TransformerAndroidTestRunner {
public static class Builder { public static class Builder {
private final Context context; private final Context context;
private final Transformer transformer; private final Transformer transformer;
private boolean maybeCalculateSsim; private boolean requestCalculateSsim;
private int timeoutSeconds; private int timeoutSeconds;
private boolean suppressAnalysisExceptions; private boolean suppressAnalysisExceptions;
@Nullable private Map<String, Object> inputValues; @Nullable private Map<String, Object> inputValues;
@ -85,22 +85,21 @@ public class TransformerAndroidTestRunner {
} }
/** /**
* Sets whether to try to calculate the SSIM of the transformation output. * Sets whether to calculate the SSIM of the transformation output compared to the input, if
* supported. Calculating SSIM is not supported if the input and output video dimensions don't
* match, or if the input video is trimmed.
* *
* <p>SSIM requires the input and output video dimensions to match. Therefore, if encoder * <p>Calculating SSIM involves decoding and comparing frames of the expected and actual videos,
* resolution fallback occurs, this calculation is skipped. * which will increase the runtime of the test.
*
* <p>The calculation involves decoding and comparing both the input and the output video.
* Consequently this calculation is not cost-free.
* *
* <p>The default value is {@code false}. * <p>The default value is {@code false}.
* *
* @param maybeCalculateSsim Whether to try to calculate SSIM. * @param requestCalculateSsim Whether to calculate SSIM, if supported.
* @return This {@link Builder}. * @return This {@link Builder}.
*/ */
@CanIgnoreReturnValue @CanIgnoreReturnValue
public Builder setMaybeCalculateSsim(boolean maybeCalculateSsim) { public Builder setRequestCalculateSsim(boolean requestCalculateSsim) {
this.maybeCalculateSsim = maybeCalculateSsim; this.requestCalculateSsim = requestCalculateSsim;
return this; return this;
} }
@ -146,7 +145,7 @@ public class TransformerAndroidTestRunner {
context, context,
transformer, transformer,
timeoutSeconds, timeoutSeconds,
maybeCalculateSsim, requestCalculateSsim,
suppressAnalysisExceptions, suppressAnalysisExceptions,
inputValues); inputValues);
} }
@ -156,7 +155,7 @@ public class TransformerAndroidTestRunner {
private final CodecNameForwardingCodecFactory transformerCodecFactory; private final CodecNameForwardingCodecFactory transformerCodecFactory;
private final Transformer transformer; private final Transformer transformer;
private final int timeoutSeconds; private final int timeoutSeconds;
private final boolean maybeCalculateSsim; private final boolean requestCalculateSsim;
private final boolean suppressAnalysisExceptions; private final boolean suppressAnalysisExceptions;
@Nullable private final Map<String, Object> inputValues; @Nullable private final Map<String, Object> inputValues;
@ -164,7 +163,7 @@ public class TransformerAndroidTestRunner {
Context context, Context context,
Transformer transformer, Transformer transformer,
int timeoutSeconds, int timeoutSeconds,
boolean maybeCalculateSsim, boolean requestCalculateSsim,
boolean suppressAnalysisExceptions, boolean suppressAnalysisExceptions,
@Nullable Map<String, Object> inputValues) { @Nullable Map<String, Object> inputValues) {
this.context = context; this.context = context;
@ -177,7 +176,7 @@ public class TransformerAndroidTestRunner {
.setEncoderFactory(transformerCodecFactory) .setEncoderFactory(transformerCodecFactory)
.build(); .build();
this.timeoutSeconds = timeoutSeconds; this.timeoutSeconds = timeoutSeconds;
this.maybeCalculateSsim = maybeCalculateSsim; this.requestCalculateSsim = requestCalculateSsim;
this.suppressAnalysisExceptions = suppressAnalysisExceptions; this.suppressAnalysisExceptions = suppressAnalysisExceptions;
this.inputValues = inputValues; this.inputValues = inputValues;
} }
@ -229,7 +228,7 @@ public class TransformerAndroidTestRunner {
private TransformationTestResult runInternal(String testId, MediaItem mediaItem) private TransformationTestResult runInternal(String testId, MediaItem mediaItem)
throws InterruptedException, IOException, TimeoutException, TransformationException { throws InterruptedException, IOException, TimeoutException, TransformationException {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET) if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& maybeCalculateSsim) { && requestCalculateSsim) {
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"SSIM calculation is not supported for clipped inputs."); "SSIM calculation is not supported for clipped inputs.");
} }
@ -323,7 +322,7 @@ public class TransformerAndroidTestRunner {
.setFilePath(outputVideoFile.getPath()) .setFilePath(outputVideoFile.getPath())
.setElapsedTimeMs(elapsedTimeMs); .setElapsedTimeMs(elapsedTimeMs);
if (!maybeCalculateSsim) { if (!requestCalculateSsim) {
return resultBuilder.build(); return resultBuilder.build();
} }
if (fallbackResolutionApplied.get()) { if (fallbackResolutionApplied.get()) {

View File

@ -67,7 +67,7 @@ public final class TranscodeQualityTest {
TransformationTestResult result = TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run( .run(
testId, testId,
@ -104,7 +104,7 @@ public final class TranscodeQualityTest {
TransformationTestResult result = TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run( .run(
testId, testId,
@ -134,7 +134,7 @@ public final class TranscodeQualityTest {
TransformationTestResult result = TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run( .run(
testId, testId,

View File

@ -55,7 +55,7 @@ public class TransformationTest {
.setEncoderFactory(new ForceEncodeEncoderFactory(context)) .setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build(); .build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)));
} }
@ -86,7 +86,7 @@ public class TransformationTest {
.build())) .build()))
.build(); .build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)));
} }
@ -109,7 +109,7 @@ public class TransformationTest {
.setEncoderFactory(new ForceEncodeEncoderFactory(context)) .setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build(); .build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.setTimeoutSeconds(180) .setTimeoutSeconds(180)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING)));
@ -132,7 +132,7 @@ public class TransformationTest {
.setEncoderFactory(new ForceEncodeEncoderFactory(context)) .setEncoderFactory(new ForceEncodeEncoderFactory(context))
.build(); .build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.setTimeoutSeconds(180) .setTimeoutSeconds(180)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING)));
@ -148,7 +148,7 @@ public class TransformationTest {
.setRemoveAudio(true) .setRemoveAudio(true)
.build(); .build();
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING)));
} }

View File

@ -157,7 +157,7 @@ public class BitrateAnalysisTest {
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setInputValues(inputValues) .setInputValues(inputValues)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(fileUri))); .run(testId, MediaItem.fromUri(Uri.parse(fileUri)));
} }

View File

@ -306,7 +306,7 @@ public class SsimMapperTest {
double ssim = double ssim =
new TransformerAndroidTestRunner.Builder(context, transformer) new TransformerAndroidTestRunner.Builder(context, transformer)
.setInputValues(inputValues) .setInputValues(inputValues)
.setMaybeCalculateSsim(true) .setRequestCalculateSsim(true)
.build() .build()
.run(testId, MediaItem.fromUri(Uri.parse(videoUri))) .run(testId, MediaItem.fromUri(Uri.parse(videoUri)))
.ssim; .ssim;