mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Record transformation duration in TransformerAndroidTestRunner.
The change will be useful in testing transcoding performance PiperOrigin-RevId: 432956283
This commit is contained in:
parent
743c6cf5f8
commit
5ab32b6e0d
2 changed files with 18 additions and 5 deletions
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.MediaItem;
|
import androidx.media3.common.MediaItem;
|
||||||
import androidx.media3.common.util.Log;
|
import androidx.media3.common.util.Log;
|
||||||
|
import androidx.media3.common.util.SystemClock;
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
import androidx.test.platform.app.InstrumentationRegistry;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
|
|
@ -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 {
|
||||||
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 {
|
||||||
.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 {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue