Skip to content

Commit

Permalink
Clarify SSIM request method name
Browse files Browse the repository at this point in the history
`requestCalculateSsim` more clearly represents the intention of the caller.

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

PiperOrigin-RevId: 465575578
  • Loading branch information
andrewlewis authored and marcbaechinger committed Oct 19, 2022
1 parent 6e4fc47 commit d90d7d3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Object> inputValues;
Expand Down Expand Up @@ -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.
*
* <p>SSIM requires the input and output video dimensions to match. Therefore, if encoder
* resolution fallback occurs, this calculation is skipped.
*
* <p>The calculation involves decoding and comparing both the input and the output video.
* Consequently this calculation is not cost-free.
* <p>Calculating SSIM involves decoding and comparing frames of the expected and actual videos,
* which will increase the runtime of the test.
*
* <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}.
*/
@CanIgnoreReturnValue
public Builder setMaybeCalculateSsim(boolean maybeCalculateSsim) {
this.maybeCalculateSsim = maybeCalculateSsim;
public Builder setRequestCalculateSsim(boolean requestCalculateSsim) {
this.requestCalculateSsim = requestCalculateSsim;
return this;
}

Expand Down Expand Up @@ -146,7 +145,7 @@ public TransformerAndroidTestRunner build() {
context,
transformer,
timeoutSeconds,
maybeCalculateSsim,
requestCalculateSsim,
suppressAnalysisExceptions,
inputValues);
}
Expand All @@ -156,15 +155,15 @@ 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<String, Object> inputValues;

private TransformerAndroidTestRunner(
Context context,
Transformer transformer,
int timeoutSeconds,
boolean maybeCalculateSsim,
boolean requestCalculateSsim,
boolean suppressAnalysisExceptions,
@Nullable Map<String, Object> inputValues) {
this.context = context;
Expand All @@ -177,7 +176,7 @@ private TransformerAndroidTestRunner(
.setEncoderFactory(transformerCodecFactory)
.build();
this.timeoutSeconds = timeoutSeconds;
this.maybeCalculateSsim = maybeCalculateSsim;
this.requestCalculateSsim = requestCalculateSsim;
this.suppressAnalysisExceptions = suppressAnalysisExceptions;
this.inputValues = inputValues;
}
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -323,7 +322,7 @@ public void onFallbackApplied(
.setFilePath(outputVideoFile.getPath())
.setElapsedTimeMs(elapsedTimeMs);

if (!maybeCalculateSsim) {
if (!requestCalculateSsim) {
return resultBuilder.build();
}
if (fallbackResolutionApplied.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void transformHighQualityTargetingAvcToAvc1920x1080_ssimIsGreaterThan95Pe

TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true)
.setRequestCalculateSsim(true)
.build()
.run(
testId,
Expand Down Expand Up @@ -104,7 +104,7 @@ public void transcodeAvcToHevc_ssimIsGreaterThan90Percent() throws Exception {

TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true)
.setRequestCalculateSsim(true)
.build()
.run(
testId,
Expand Down Expand Up @@ -134,7 +134,7 @@ public void transcodeAvcToAvc320x240_ssimIsGreaterThan90Percent() throws Excepti

TransformationTestResult result =
new TransformerAndroidTestRunner.Builder(context, transformer)
.setMaybeCalculateSsim(true)
.setRequestCalculateSsim(true)
.build()
.run(
testId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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)));
}
Expand All @@ -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)));
Expand All @@ -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)));
Expand All @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d90d7d3

Please sign in to comment.