From d90d7d30789ec819d905fd98291f66ab7031f47b Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Fri, 5 Aug 2022 16:02:07 +0000 Subject: [PATCH] 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 --- .../TransformerAndroidTestRunner.java | 31 +++++++++---------- .../transformer/mh/TranscodeQualityTest.java | 6 ++-- .../transformer/mh/TransformationTest.java | 10 +++--- .../mh/analysis/BitrateAnalysisTest.java | 2 +- .../mh/analysis/SsimMapperTest.java | 2 +- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java index 2716c9ebdc1..d997171bcd3 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/TransformerAndroidTestRunner.java @@ -52,7 +52,7 @@ public class TransformerAndroidTestRunner { public static class Builder { private final Context context; private final Transformer transformer; - private boolean maybeCalculateSsim; + private boolean requestCalculateSsim; private int timeoutSeconds; private boolean suppressAnalysisExceptions; @Nullable private Map inputValues; @@ -85,22 +85,21 @@ public Builder setTimeoutSeconds(int timeoutSeconds) { } /** - * 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. * - *

SSIM requires the input and output video dimensions to match. Therefore, if encoder - * resolution fallback occurs, this calculation is skipped. - * - *

The calculation involves decoding and comparing both the input and the output video. - * Consequently this calculation is not cost-free. + *

Calculating SSIM involves decoding and comparing frames of the expected and actual videos, + * which will increase the runtime of the test. * *

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}. */ @CanIgnoreReturnValue - public Builder setMaybeCalculateSsim(boolean maybeCalculateSsim) { - this.maybeCalculateSsim = maybeCalculateSsim; + public Builder setRequestCalculateSsim(boolean requestCalculateSsim) { + this.requestCalculateSsim = requestCalculateSsim; return this; } @@ -146,7 +145,7 @@ public TransformerAndroidTestRunner build() { context, transformer, timeoutSeconds, - maybeCalculateSsim, + requestCalculateSsim, suppressAnalysisExceptions, inputValues); } @@ -156,7 +155,7 @@ public TransformerAndroidTestRunner build() { private final CodecNameForwardingCodecFactory transformerCodecFactory; private final Transformer transformer; private final int timeoutSeconds; - private final boolean maybeCalculateSsim; + private final boolean requestCalculateSsim; private final boolean suppressAnalysisExceptions; @Nullable private final Map inputValues; @@ -164,7 +163,7 @@ private TransformerAndroidTestRunner( Context context, Transformer transformer, int timeoutSeconds, - boolean maybeCalculateSsim, + boolean requestCalculateSsim, boolean suppressAnalysisExceptions, @Nullable Map inputValues) { this.context = context; @@ -177,7 +176,7 @@ private TransformerAndroidTestRunner( .setEncoderFactory(transformerCodecFactory) .build(); this.timeoutSeconds = timeoutSeconds; - this.maybeCalculateSsim = maybeCalculateSsim; + this.requestCalculateSsim = requestCalculateSsim; this.suppressAnalysisExceptions = suppressAnalysisExceptions; this.inputValues = inputValues; } @@ -229,7 +228,7 @@ public TransformationTestResult run(String testId, MediaItem mediaItem) throws E private TransformationTestResult runInternal(String testId, MediaItem mediaItem) throws InterruptedException, IOException, TimeoutException, TransformationException { if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET) - && maybeCalculateSsim) { + && requestCalculateSsim) { throw new UnsupportedOperationException( "SSIM calculation is not supported for clipped inputs."); } @@ -323,7 +322,7 @@ public void onFallbackApplied( .setFilePath(outputVideoFile.getPath()) .setElapsedTimeMs(elapsedTimeMs); - if (!maybeCalculateSsim) { + if (!requestCalculateSsim) { return resultBuilder.build(); } if (fallbackResolutionApplied.get()) { diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TranscodeQualityTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TranscodeQualityTest.java index 1c6fc3cb83e..f3a56283a60 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TranscodeQualityTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TranscodeQualityTest.java @@ -67,7 +67,7 @@ public void transformHighQualityTargetingAvcToAvc1920x1080_ssimIsGreaterThan95Pe TransformationTestResult result = new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run( testId, @@ -104,7 +104,7 @@ public void transcodeAvcToHevc_ssimIsGreaterThan90Percent() throws Exception { TransformationTestResult result = new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run( testId, @@ -134,7 +134,7 @@ public void transcodeAvcToAvc320x240_ssimIsGreaterThan90Percent() throws Excepti TransformationTestResult result = new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run( testId, diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java index dddf8d88a30..cedb49426f3 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/TransformationTest.java @@ -55,7 +55,7 @@ public void transform() throws Exception { .setEncoderFactory(new ForceEncodeEncoderFactory(context)) .build(); new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); } @@ -86,7 +86,7 @@ public void transformToSpecificBitrate() throws Exception { .build())) .build(); new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); } @@ -109,7 +109,7 @@ public void transform4K60() throws Exception { .setEncoderFactory(new ForceEncodeEncoderFactory(context)) .build(); new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .setTimeoutSeconds(180) .build() .run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_4K60_PORTRAIT_URI_STRING))); @@ -132,7 +132,7 @@ public void transform8K24() throws Exception { .setEncoderFactory(new ForceEncodeEncoderFactory(context)) .build(); new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .setTimeoutSeconds(180) .build() .run(testId, MediaItem.fromUri(Uri.parse(MP4_REMOTE_8K24_URI_STRING))); @@ -148,7 +148,7 @@ public void transformNoAudio() throws Exception { .setRemoveAudio(true) .build(); new TransformerAndroidTestRunner.Builder(context, transformer) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run(testId, MediaItem.fromUri(Uri.parse(MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING))); } diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/BitrateAnalysisTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/BitrateAnalysisTest.java index c0e679f649a..f3903aecad4 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/BitrateAnalysisTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/BitrateAnalysisTest.java @@ -157,7 +157,7 @@ public void analyzeBitrate() throws Exception { new TransformerAndroidTestRunner.Builder(context, transformer) .setInputValues(inputValues) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run(testId, MediaItem.fromUri(Uri.parse(fileUri))); } diff --git a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/SsimMapperTest.java b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/SsimMapperTest.java index 334f7b57368..6e1f446fd17 100644 --- a/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/SsimMapperTest.java +++ b/library/transformer/src/androidTest/java/com/google/android/exoplayer2/transformer/mh/analysis/SsimMapperTest.java @@ -306,7 +306,7 @@ private double transformAndGetSsim(int bitrate) throws Exception { double ssim = new TransformerAndroidTestRunner.Builder(context, transformer) .setInputValues(inputValues) - .setMaybeCalculateSsim(true) + .setRequestCalculateSsim(true) .build() .run(testId, MediaItem.fromUri(Uri.parse(videoUri))) .ssim;