Commit 661d7dde by claincly Committed by Ian Baker

Record transformation duration in TransformerAndroidTestRunner.

The change will be useful in testing transcoding performance

PiperOrigin-RevId: 432956283
parent 3877171f
...@@ -22,17 +22,24 @@ public class TransformationTestResult { ...@@ -22,17 +22,24 @@ public class TransformationTestResult {
public final TransformationResult transformationResult; public final TransformationResult transformationResult;
public final String filePath; public final String filePath;
/** The amount of time taken to perform the transformation in milliseconds. */
public final long transformationDurationMs;
/** The SSIM score of the transformation, {@link #SSIM_UNSET} if unavailable. */ /** The SSIM score of the transformation, {@link #SSIM_UNSET} if unavailable. */
public final double ssim; public final double ssim;
public TransformationTestResult(TransformationResult transformationResult, String filePath) { public TransformationTestResult(
this(transformationResult, filePath, /* ssim= */ SSIM_UNSET); TransformationResult transformationResult, String filePath, long transformationDurationMs) {
this(transformationResult, filePath, transformationDurationMs, /* ssim= */ SSIM_UNSET);
} }
public TransformationTestResult( public TransformationTestResult(
TransformationResult transformationResult, String filePath, double ssim) { TransformationResult transformationResult,
String filePath,
long transformationDurationMs,
double ssim) {
this.transformationResult = transformationResult; this.transformationResult = transformationResult;
this.filePath = filePath; this.filePath = filePath;
this.transformationDurationMs = transformationDurationMs;
this.ssim = ssim; this.ssim = ssim;
} }
} }
...@@ -26,6 +26,7 @@ import androidx.test.platform.app.InstrumentationRegistry; ...@@ -26,6 +26,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.SystemClock;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
...@@ -157,6 +158,7 @@ public class TransformerAndroidTestRunner { ...@@ -157,6 +158,7 @@ public class TransformerAndroidTestRunner {
AtomicReference<@NullableType TransformationResult> transformationResultReference = AtomicReference<@NullableType TransformationResult> transformationResultReference =
new AtomicReference<>(); new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(1); CountDownLatch countDownLatch = new CountDownLatch(1);
long startTimeMs = SystemClock.DEFAULT.elapsedRealtime();
Transformer testTransformer = Transformer testTransformer =
transformer transformer
...@@ -199,6 +201,7 @@ public class TransformerAndroidTestRunner { ...@@ -199,6 +201,7 @@ public class TransformerAndroidTestRunner {
if (!countDownLatch.await(timeoutSeconds, SECONDS)) { if (!countDownLatch.await(timeoutSeconds, SECONDS)) {
throw new TimeoutException("Transformer timed out after " + timeoutSeconds + " seconds."); throw new TimeoutException("Transformer timed out after " + timeoutSeconds + " seconds.");
} }
long transformationDurationMs = SystemClock.DEFAULT.elapsedRealtime() - startTimeMs;
@Nullable Exception unexpectedException = unexpectedExceptionReference.get(); @Nullable Exception unexpectedException = unexpectedExceptionReference.get();
if (unexpectedException != null) { if (unexpectedException != null) {
...@@ -220,13 +223,15 @@ public class TransformerAndroidTestRunner { ...@@ -220,13 +223,15 @@ public class TransformerAndroidTestRunner {
.build(); .build();
if (!calculateSsim) { if (!calculateSsim) {
return new TransformationTestResult(transformationResult, outputVideoFile.getPath()); return new TransformationTestResult(
transformationResult, outputVideoFile.getPath(), transformationDurationMs);
} }
double ssim = double ssim =
SsimHelper.calculate( SsimHelper.calculate(
context, /* expectedVideoPath= */ uriString, outputVideoFile.getPath()); context, /* expectedVideoPath= */ uriString, outputVideoFile.getPath());
return new TransformationTestResult(transformationResult, outputVideoFile.getPath(), ssim); return new TransformationTestResult(
transformationResult, outputVideoFile.getPath(), transformationDurationMs, ssim);
} }
private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson) private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson)
...@@ -270,6 +275,7 @@ public class TransformerAndroidTestRunner { ...@@ -270,6 +275,7 @@ public class TransformerAndroidTestRunner {
if (testResult.ssim != TransformationTestResult.SSIM_UNSET) { if (testResult.ssim != TransformationTestResult.SSIM_UNSET) {
transformationResultJson.put("ssim", testResult.ssim); transformationResultJson.put("ssim", testResult.ssim);
} }
transformationResultJson.put("transformationDurationMs", testResult.transformationDurationMs);
return transformationResultJson; return transformationResultJson;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment